In geotools ,how to use Geometry as feature source add into layer? - java

In geotools ,how to use geometry as feature source add into layers?
I know that .shp file can add into layers, and add into content,then we can show it.
I read it in geotools quickstart:
http://docs.geotools.org/latest/userguide/tutorial/quickstart/intellij.html
but I want to show the geometry object in content, I need to use geometry object as feature source replace shap file.(It's right?)
So how to do it? I only konw that how to get geometry's WKT and geojson.
thank you!

GeoTools will only display Features so you need to create a Feature and add your Geometry object to the feature. You will also need to know the projection of your geometry if you plan to display it with other data sets (e.g. shapefiles).
If you look at the Feature Tutorial you will see a worked example of how to create a FeatureType and how to make Features using it. The QuickStart tutorial shows how to display features on the screen.
The utility class DataUtilities provides methods for converting lists of features to FeatureCollections and FeatureSources.
You mention WKT and GeoJSON as possible sources so you will want to explore the JTS.WKTReader and the gt-geojson module for help parsing those formats into Geometries that GeoTools can make use of.

Related

Elki plots from pure Java API

I've been searching for a way to export ELKI generated visualization into SVG file, which can later be displayed on my application. However, I could not find any example code which uses typical java constructors. My goals are:
input Results in a Visualization.
set VisualizerParameterizer constructor, adding the previous Visualization.
set ExportVisualizations constructor properly to write the file.
For instance, let's say I already have an OutlierResult instance and now I want to plot the scores using BubbleVisualization and produce an SVG file? How can I do that using the pure Java API?
Some classes like VisualizerParameterizer can be a bit annoying to set up manually, because this involves finding all desired visualization factories from the service loader - there is a plug-in layer there, that allows to add new visualizations to be rendered automatically.
Because of this, the easiest way is to use the parameterization API, for example (git style):
ExportVisualizations export = new ELKIBuilder<>(ExportVisualizations.class)
.with(ExportVisualizations.Parameterizer.FOLDER_ID, "folder")
.build();
or if you are still using an old release / do not like builders:
ListParameterization params = new ListParameterization();
params.addParameter(ExportVisualizations.Parameterizer.FOLDER_ID, "folder");
ExportVisualizations export = ClassGenericsUtil.parameterizeOrAbort(
ExportVisualizations.class, params);
Because you only need to give mandatory parameters, and it can construct nested objects. In this case, it will also construct the VisualizerParameterizer, so you can also add options for that class, such as
.with(VisualizerParameterizer.Parameterizer.ENABLEVIS_ID, "scatter")
to only enable scatter plot visualizations.

Creating and training a model for OpenNlp using BRAT?

I may need to create a custom training set for OpenNLP, and this will require me to manually annotate a lot of entries.
To make things easier, a GUI solution may be the best idea (manually writing annotation tags it's not cool), and I've just discovered BRAT which looks like what I need.
BRAT can export an annotated file (.ann), but I'm not finding any reference to this filetype in OpenNLP's manual and I'm not sure that this can work.
What I'd like to do is to export this annotated file from BRAT and use it to train an OpenNLP's model, and I don't really care if it can be done using code or CLI.
Can someone point me in the right direction?
OpenNLP has native support for the BRAT format for training and evaluation of the Name Finder. Other components are not supported currently. Adding support for other components would probably not be difficult and in case you are interested you should ask for it on the opennlp-dev list.
The CLI can be used to train a model with brat, here is the command which will show you the usage:
bin/opennlp TokenNameFinderTrainer.brat
The following arguments are mandatory to train a model:
bratDataDir this should point to a folder containing your .ann and .txt files
annotationConfig this has to point to the config file brat is using for annotation project
lang the language of your text documents (e.g. en)
model the name of the created model file
The Name Finder needs its input cut into sentences and into tokens. By default it assumes one sentence per line and applies white space tokenization. This behavior can be adjusted with the ruleBasedTokenizer or tokenizerModel arguments. Additional it is possible to use a custom sentence detector model via the sentenceDetector Model argument.
To evaluate your model the cross validation and evaluation tools can be used in a simliar way by attaching .brat to their names.
bin/opennlp TokenNameFinderCrossValidator.brat
bin/opennlp TokenNameFinderEvaluator.brat
To speed up your annotation project you can use the opennlp-brat-annotator. It can load the Name Finder model and integrates with BRAT to automatically annotate your documents. This can speed up your annotation effort. You can find that component in the opennlp sandbox.

Java JSON editor / visualizer

I wrote an application that takes a JSON file as configuration. Up to this point, I wrote the JSON config by hand. However, now I want to allow other users who are not familiar with JSON format to make their own configurations. There's only 3 types of objects that the configuration needs to store, but the user should be allowed to add multiple copies of these objects. I want to write a configuration application where the user can press a button such as "Add Type A" and an object of type A is populated with default values and visualized so that the user can select properties and edit them. I know how to write an application that does this, but I feel like I'm re-inventing the wheel. Does anyone know of an open-source Java library that I can use inside my config application to handle visualization and editing a JSON file? If I'm approaching this from completely the wrong direction, please let me know.
I'm tempted to say "don't fear to reinvent the wheel".
But the fact is that there a bunch solutions available :
How do I convert an object to JSON representation (and vice-versa)
Java representation of JSON Object
Javascript to Java using JSON
among them, GSON looks fine.
For my personal experience, Yaml turned out to be an appropriate solution.

HCSP to JSON through JAVA

I ve a HCSP File used by stellent(oracle product) and need of business is to convert a hcsp file to JSON format via java programming. Is there any standard way existing that I might not be aware of? Please give a pointer how to go for such conversion.
There might be a few core Java classes that could assist in this. Some of these are used when IsJson=1 is added in the URL.
Do you need a specific JSON layout? What does your HTML look like?

Country border coordinate data

I'm writing a geography game in Java, and I'd like to have some data on the locations of the borders of countries, but all I can find is shapefiles, and I can't get latitude/longitude data out of them, or else I can only find a single coordinate for each country.
Where can I find
a way to extract the longitude/latitude data into usable data in Java or in a text file?
a web site with free data on country borders that can be used in a java program?
Edit:
It doesn't need to be exact; for pretty much anything except Russia, China the U.S., and Brazil, 10 coordinates is probably enough. Islands don't really matter either. I just want to know be able to calculate relatively accurately the shortest distance between two countries.
Download the generalized Country borders from here: http://www.baruch.cuny.edu/geoportal/data/esri/esri_intl.htm. These are probably more detailed than you want (Canada has the most vertices at 3316), but is the only free rough border data set I could find online.
To get the coordinates from a shapefile as text, go to MyGeodata Converter
Run Vector Converter
Upload the zip file you just downloaded.
Check available operations
Export to GeoJSON
Download Zip file form MyGeodata Converter
Unzip the file.
Now you have the boundaries in GeoJSON format and can use a GeoJSON parser or a more simple text parser to get the coordinate data.
If that's too much work, you can also parse shapefiles with one of the various Java shapefile frameworks out there. See Does anyone know of a library in Java that can parse ESRI Shapefiles? for some options.
Download the osm file and import into postgresql+postgis(via osm2pgsql tool will do).
If you required another database migrate postgresql to your desired database
http://planet.openstreetmap.org/
The MyGeodata converter only throws a 500 error at the moment, so I had to look further and finally stumbled across KML files that roughly describe the outline of each country. I posted the link on this related question, so someone might want to look there.

Categories

Resources