use of com.vividsolutions.jts.geom.Coordinate in project GeoGig by boundlessgeo.
the class OSMUnmapOpTest method testMappingAndUnmappingOfNodes.
@Test
public void testMappingAndUnmappingOfNodes() throws Exception {
// Import
String filename = OSMImportOp.class.getResource("nodes.xml").getFile();
File file = new File(filename);
geogig.command(OSMImportOp.class).setDataSource(file.getAbsolutePath()).call();
geogig.command(AddOp.class).call();
geogig.command(CommitOp.class).setMessage("msg").call();
// Map
Map<String, AttributeDefinition> fields = Maps.newHashMap();
Map<String, List<String>> mappings = Maps.newHashMap();
mappings.put("highway", Lists.newArrayList("bus_stop"));
fields.put("geom", new AttributeDefinition("geom", FieldType.POINT));
fields.put("name", new AttributeDefinition("name", FieldType.STRING));
Map<String, List<String>> filterExclude = Maps.newHashMap();
MappingRule mappingRule = new MappingRule("busstops", mappings, filterExclude, fields, null);
List<MappingRule> mappingRules = Lists.newArrayList();
mappingRules.add(mappingRule);
Mapping mapping = new Mapping(mappingRules);
geogig.command(OSMMapOp.class).setMapping(mapping).call();
Optional<RevFeature> revFeature = geogig.command(RevObjectParse.class).setRefSpec("HEAD:busstops/507464799").call(RevFeature.class);
assertTrue(revFeature.isPresent());
Optional<RevFeatureType> featureType = geogig.command(ResolveFeatureType.class).setRefSpec("HEAD:busstops/507464799").call();
assertTrue(featureType.isPresent());
ImmutableList<Optional<Object>> values = revFeature.get().getValues();
assertEquals(3, values.size());
String wkt = "POINT (7.1959361 50.739397)";
assertEquals(wkt, values.get(2).get().toString());
assertEquals(507464799l, values.get(0).get());
// Modify a node
GeometryFactory gf = new GeometryFactory();
SimpleFeatureBuilder fb = new SimpleFeatureBuilder((SimpleFeatureType) featureType.get().type());
fb.set("geom", gf.createPoint(new Coordinate(0, 1)));
fb.set("name", "newname");
fb.set("id", 507464799l);
SimpleFeature newFeature = fb.buildFeature("507464799");
geogig.getRepository().workingTree().insert("busstops", newFeature);
// check that it was correctly inserted in the working tree
Optional<RevFeature> mapped = geogig.command(RevObjectParse.class).setRefSpec("WORK_HEAD:busstops/507464799").call(RevFeature.class);
assertTrue(mapped.isPresent());
values = mapped.get().getValues();
assertEquals("POINT (0 1)", values.get(2).get().toString());
assertEquals(507464799l, ((Long) values.get(0).get()).longValue());
assertEquals("newname", values.get(1).get().toString());
// unmap
geogig.command(OSMUnmapOp.class).setPath("busstops").call();
// check that the unmapped node has the changes we introduced
Optional<RevFeature> unmapped = geogig.command(RevObjectParse.class).setRefSpec("WORK_HEAD:node/507464799").call(RevFeature.class);
assertTrue(unmapped.isPresent());
values = unmapped.get().getValues();
assertEquals("POINT (0 1)", values.get(6).get().toString());
assertEquals("bus:yes|public_transport:platform|highway:bus_stop|VRS:ortsteil:Hoholz|name:newname|VRS:ref:68566|VRS:gemeinde:BONN", values.get(3).get().toString());
// check that unchanged nodes keep their attributes
Optional<RevFeature> unchanged = geogig.command(RevObjectParse.class).setRefSpec("WORK_HEAD:node/1633594723").call(RevFeature.class);
values = unchanged.get().getValues();
assertEquals("14220478", values.get(4).get().toString());
assertEquals("1355097351000", values.get(2).get().toString());
assertEquals("2", values.get(1).get().toString());
}
use of com.vividsolutions.jts.geom.Coordinate in project GeoGig by boundlessgeo.
the class OSMUnmapOpTest method testMappingAndUnmappingOfNodesWithAlias.
@Test
public void testMappingAndUnmappingOfNodesWithAlias() throws Exception {
// Import
String filename = OSMImportOp.class.getResource("nodes.xml").getFile();
File file = new File(filename);
geogig.command(OSMImportOp.class).setDataSource(file.getAbsolutePath()).call();
geogig.command(AddOp.class).call();
geogig.command(CommitOp.class).setMessage("msg").call();
// Map
Map<String, AttributeDefinition> fields = Maps.newHashMap();
Map<String, List<String>> mappings = Maps.newHashMap();
mappings.put("highway", Lists.newArrayList("bus_stop"));
fields.put("geom", new AttributeDefinition("geom", FieldType.POINT));
fields.put("name", new AttributeDefinition("name_alias", FieldType.STRING));
Map<String, List<String>> filterExclude = Maps.newHashMap();
MappingRule mappingRule = new MappingRule("busstops", mappings, filterExclude, fields, null);
List<MappingRule> mappingRules = Lists.newArrayList();
mappingRules.add(mappingRule);
Mapping mapping = new Mapping(mappingRules);
geogig.command(OSMMapOp.class).setMapping(mapping).call();
Optional<RevFeature> revFeature = geogig.command(RevObjectParse.class).setRefSpec("HEAD:busstops/507464799").call(RevFeature.class);
assertTrue(revFeature.isPresent());
Optional<RevFeatureType> featureType = geogig.command(ResolveFeatureType.class).setRefSpec("HEAD:busstops/507464799").call();
assertTrue(featureType.isPresent());
ImmutableList<Optional<Object>> values = revFeature.get().getValues();
assertEquals(3, values.size());
String wkt = "POINT (7.1959361 50.739397)";
assertEquals(wkt, values.get(2).get().toString());
assertEquals(507464799l, values.get(0).get());
// unmap without having made any changes and check that the canonical folders are not
// modified
geogig.command(OSMUnmapOp.class).setPath("busstops").call();
WorkingTree workTree = geogig.getRepository().workingTree();
long unstaged = workTree.countUnstaged("way").count();
assertEquals(0, unstaged);
unstaged = workTree.countUnstaged("node").count();
assertEquals(0, unstaged);
// Modify a node
GeometryFactory gf = new GeometryFactory();
SimpleFeatureBuilder fb = new SimpleFeatureBuilder((SimpleFeatureType) featureType.get().type());
fb.set("geom", gf.createPoint(new Coordinate(0, 1)));
fb.set("name_alias", "newname");
fb.set("id", 507464799l);
SimpleFeature newFeature = fb.buildFeature("507464799");
geogig.getRepository().workingTree().insert("busstops", newFeature);
// check that it was correctly inserted in the working tree
Optional<RevFeature> mapped = geogig.command(RevObjectParse.class).setRefSpec("WORK_HEAD:busstops/507464799").call(RevFeature.class);
assertTrue(mapped.isPresent());
values = mapped.get().getValues();
assertEquals("POINT (0 1)", values.get(2).get().toString());
assertEquals(507464799l, ((Long) values.get(0).get()).longValue());
assertEquals("newname", values.get(1).get().toString());
// unmap
geogig.command(OSMUnmapOp.class).setPath("busstops").call();
unstaged = workTree.countUnstaged("node").featureCount();
assertEquals(1, unstaged);
// check that the unmapped node has the changes we introduced
Optional<RevFeature> unmapped = geogig.command(RevObjectParse.class).setRefSpec("WORK_HEAD:node/507464799").call(RevFeature.class);
assertTrue(unmapped.isPresent());
values = unmapped.get().getValues();
assertEquals("POINT (0 1)", values.get(6).get().toString());
assertEquals("bus:yes|public_transport:platform|highway:bus_stop|VRS:ortsteil:Hoholz|name:newname|VRS:ref:68566|VRS:gemeinde:BONN", values.get(3).get().toString());
// check that unchanged nodes keep their attributes
Optional<RevFeature> unchanged = geogig.command(RevObjectParse.class).setRefSpec("WORK_HEAD:node/1633594723").call(RevFeature.class);
values = unchanged.get().getValues();
assertEquals("14220478", values.get(4).get().toString());
assertEquals("1355097351000", values.get(2).get().toString());
assertEquals("2", values.get(1).get().toString());
}
use of com.vividsolutions.jts.geom.Coordinate in project StreetComplete by westnordost.
the class FindQuestSourceComponent method createLocationsGeometry.
private Geometry createLocationsGeometry(List<Location> locations) {
if (locations == null || locations.isEmpty())
return null;
if (locations.size() == 1) {
Location location = locations.get(0);
return geometryFactory.createPoint(createCoordinate(location));
}
Coordinate[] coordinates = new Coordinate[locations.size()];
for (int i = 0; i < locations.size(); ++i) {
Location location = locations.get(i);
coordinates[i] = createCoordinate(location);
}
return geometryFactory.createLineString(coordinates);
}
use of com.vividsolutions.jts.geom.Coordinate in project StreetComplete by westnordost.
the class JTSConst method toCoordinates.
public static Coordinate[] toCoordinates(List<LatLon> latLons) {
Coordinate[] result = new Coordinate[latLons.size()];
int i = 0;
for (LatLon latLon : latLons) {
result[i++] = toCoordinate(latLon);
}
return result;
}
use of com.vividsolutions.jts.geom.Coordinate in project janusgraph by JanusGraph.
the class GeoshapeTest method testGeoJsonMultiPolygon.
@Test
public void testGeoJsonMultiPolygon() throws IOException {
Geoshape.GeoshapeSerializer s = new Geoshape.GeoshapeSerializer();
Map json = new ObjectMapper().readValue("{\n" + " \"type\": \"Feature\",\n" + " \"geometry\": {\n" + " \"type\": \"MultiPolygon\",\n" + " \"coordinates\": [[[[102.0,2.0],[103.0,2.0],[103.0,3.0],[102.0,3.0],[102.0,2.0]]]," + "[[[100.0,0.0],[101.0,0.0],[101.0,1.0],[100.0,1.0],[100.0,0.0]],[[100.2,0.2],[100.8,0.2],[100.8,0.8],[100.2,0.8],[100.2,0.2]]]]\n" + " }" + "}", HashMap.class);
assertEquals(HELPER.geoshape(GF.createMultiPolygon(new Polygon[] { GF.createPolygon(new Coordinate[] { new Coordinate(102, 2), new Coordinate(103, 2), new Coordinate(103, 3), new Coordinate(102, 3), new Coordinate(102, 2) }), GF.createPolygon(GF.createLinearRing(new Coordinate[] { new Coordinate(100, 0), new Coordinate(101, 0), new Coordinate(101, 1), new Coordinate(100, 1), new Coordinate(100, 0) }), new LinearRing[] { GF.createLinearRing(new Coordinate[] { new Coordinate(100.2, 0.2), new Coordinate(100.8, 0.2), new Coordinate(100.8, 0.8), new Coordinate(100.2, 0.8), new Coordinate(100.2, 0.2) }) }) })), s.convert(json));
}
Aggregations