Java Code Examples for com.vividsolutions.jts.geom.GeometryFactory#createLinearRing()
The following examples show how to use
com.vividsolutions.jts.geom.GeometryFactory#createLinearRing() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SearchByLocationCommandTest.java From geomajas-project-server with GNU Affero General Public License v3.0 | 6 votes |
@Test public void intersect50percentOverlapAlmost() throws Exception { // prepare command SearchByLocationRequest request = new SearchByLocationRequest(); request.setCrs("EPSG:4326"); request.setQueryType(SearchByLocationRequest.QUERY_INTERSECTS); request.setSearchType(SearchByLocationRequest.SEARCH_ALL_LAYERS); request.setRatio(0.5f); request.setLayerIds(new String[] {LAYER_ID}); // create a rectangle that overlaps 49 % GeometryFactory factory = new GeometryFactory(); LinearRing half1 = factory.createLinearRing(new Coordinate[] {new Coordinate(0, 0), new Coordinate(1, 0), new Coordinate(1, 0.49), new Coordinate(0, 0.49), new Coordinate(0, 0)}); Polygon polygon = factory.createPolygon(half1, null); request.setLocation(converter.toDto(polygon)); // execute SearchByLocationResponse response = (SearchByLocationResponse) dispatcher.execute( SearchByLocationRequest.COMMAND, request, null, "en"); // test List<Feature> features = response.getFeatureMap().get(LAYER_ID); Assert.assertNull(features); }
Example 2
Source File: GeoJsonReader.java From jts with GNU Lesser General Public License v2.1 | 5 votes |
private Geometry createPolygon(Map<String, Object> geometryMap, GeometryFactory geometryFactory) throws ParseException { Geometry result = null; try { @SuppressWarnings("unchecked") List<List<List<Number>>> ringsList = (List<List<List<Number>>>) geometryMap .get(GeoJsonConstants.NAME_COORDINATES); List<CoordinateSequence> rings = new ArrayList<CoordinateSequence>(); for (List<List<Number>> coordinates : ringsList) { rings.add(createCoordinateSequence(coordinates)); } if (rings.isEmpty()) { throw new IllegalArgumentException("Polygon specified with no rings."); } LinearRing outer = geometryFactory.createLinearRing(rings.get(0)); LinearRing[] inner = null; if (rings.size() > 1) { inner = new LinearRing[rings.size() - 1]; for (int i = 1; i < rings.size(); i++) { inner[i - 1] = geometryFactory.createLinearRing(rings.get(i)); } } result = geometryFactory.createPolygon(outer, inner); } catch (RuntimeException e) { throw new ParseException("Could not parse Polygon from GeoJson string.", e); } return result; }
Example 3
Source File: QuadEdgeTriangle.java From jts with GNU Lesser General Public License v2.1 | 5 votes |
public static Geometry toPolygon(Vertex[] v) { Coordinate[] ringPts = new Coordinate[] { v[0].getCoordinate(), v[1].getCoordinate(), v[2].getCoordinate(), v[0].getCoordinate() }; GeometryFactory fact = new GeometryFactory(); LinearRing ring = fact.createLinearRing(ringPts); Polygon tri = fact.createPolygon(ring, null); return tri; }
Example 4
Source File: QuadEdgeTriangle.java From jts with GNU Lesser General Public License v2.1 | 5 votes |
public static Geometry toPolygon(QuadEdge[] e) { Coordinate[] ringPts = new Coordinate[] { e[0].orig().getCoordinate(), e[1].orig().getCoordinate(), e[2].orig().getCoordinate(), e[0].orig().getCoordinate() }; GeometryFactory fact = new GeometryFactory(); LinearRing ring = fact.createLinearRing(ringPts); Polygon tri = fact.createPolygon(ring, null); return tri; }
Example 5
Source File: StyleConverterServiceImpl.java From geomajas-project-server with GNU Affero General Public License v3.0 | 5 votes |
private LinearRing toLinearRing(GeometryFactory factory, LinearRingTypeInfo linearRing) throws LayerException { LinearRing ring = null; if (linearRing.ifCoordList()) { ring = factory.createLinearRing(getCoordinates(linearRing.getCoordList())); } else if (linearRing.ifCoordinates()) { ring = factory.createLinearRing(getCoordinates(linearRing.getCoordinates())); } return ring; }
Example 6
Source File: BeanLayerTest.java From geomajas-project-server with GNU Affero General Public License v3.0 | 5 votes |
@Test public void readGeometry() throws LayerException { Object bean = layer.read("1"); GeometryFactory factory = new GeometryFactory(new PrecisionModel(), 4326); LinearRing shell = factory.createLinearRing(new Coordinate[] { new Coordinate(0, 0), new Coordinate(1, 0), new Coordinate(1, 1), new Coordinate(0, 1), new Coordinate(0, 0), }); Polygon p = factory.createPolygon(shell, null); MultiPolygon expected =factory.createMultiPolygon(new Polygon[]{p}); Geometry g = layer.getFeatureModel().getGeometry(bean); Assert.assertTrue(expected.equalsExact(g, 0.00001)); }
Example 7
Source File: CustomBeanLayerTest.java From geomajas-project-server with GNU Affero General Public License v3.0 | 5 votes |
@Before public void setupBeans() throws LayerException { GeometryFactory factory = new GeometryFactory(new PrecisionModel(PrecisionModel.FLOATING), 4329); LinearRing shell = factory.createLinearRing(new Coordinate[] { new Coordinate(0, 0), new Coordinate(1, 0), new Coordinate(1, 1), new Coordinate(0, 1), new Coordinate(0, 0), }); Polygon p = factory.createPolygon(shell, null); MultiPolygon expected = factory.createMultiPolygon(new Polygon[] { p }); CustomBean cb = new CustomBean(); cb.setId(1); cb.setGeometry(expected); cb.setName("testbean"); layer.saveOrUpdate(cb); }
Example 8
Source File: CustomBeanLayerTest.java From geomajas-project-server with GNU Affero General Public License v3.0 | 5 votes |
@Test public void readGeometry() throws LayerException { GeometryFactory factory = new GeometryFactory(new PrecisionModel(), 4326); LinearRing shell = factory.createLinearRing(new Coordinate[] { new Coordinate(0, 0), new Coordinate(1, 0), new Coordinate(1, 1), new Coordinate(0, 1), new Coordinate(0, 0), }); Polygon p = factory.createPolygon(shell, null); MultiPolygon expected = factory.createMultiPolygon(new Polygon[] { p }); Assert.assertTrue(((CustomBean) layer.read("1")).getGeometry().equalsExact(expected)); }
Example 9
Source File: SearchByLocationCommandTest.java From geomajas-project-server with GNU Affero General Public License v3.0 | 5 votes |
@Test public void intersect50percentOverlapExactly() throws Exception { // prepare command SearchByLocationRequest request = new SearchByLocationRequest(); request.setCrs("EPSG:4326"); request.setQueryType(SearchByLocationRequest.QUERY_INTERSECTS); request.setSearchType(SearchByLocationRequest.SEARCH_ALL_LAYERS); request.setRatio(0.5f); request.setLayerIds(new String[] {LAYER_ID}); // create a rectangle that overlaps 50 % GeometryFactory factory = new GeometryFactory(); LinearRing half1 = factory.createLinearRing(new Coordinate[] {new Coordinate(0, 0), new Coordinate(1, 0), new Coordinate(1, 0.5), new Coordinate(0, 0.5), new Coordinate(0, 0)}); Polygon polygon = factory.createPolygon(half1, null); request.setLocation(converter.toDto(polygon)); // execute SearchByLocationResponse response = (SearchByLocationResponse) dispatcher.execute( SearchByLocationRequest.COMMAND, request, null, "en"); // test Assert.assertFalse(response.isError()); List<Feature> features = response.getFeatureMap().get(LAYER_ID); Assert.assertNotNull(features); List<String> actual = new ArrayList<String>(); for (Feature feature : features) { actual.add(feature.getLabel()); } List<String> expected = new ArrayList<String>(); expected.add("Country 1"); Assert.assertEquals(expected, actual); }
Example 10
Source File: GeoJsonReader.java From jts with GNU Lesser General Public License v2.1 | 4 votes |
private Geometry createMultiPolygon(Map<String, Object> geometryMap, GeometryFactory geometryFactory) throws ParseException { Geometry result = null; try { @SuppressWarnings("unchecked") List<List<List<List<Number>>>> polygonsList = (List<List<List<List<Number>>>>) geometryMap .get(GeoJsonConstants.NAME_COORDINATES); Polygon[] polygons = new Polygon[polygonsList.size()]; int p = 0; for (List<List<List<Number>>> ringsList : polygonsList) { List<CoordinateSequence> rings = new ArrayList<CoordinateSequence>(); for (List<List<Number>> coordinates : ringsList) { rings.add(createCoordinateSequence(coordinates)); } if (rings.isEmpty()) { continue; } LinearRing outer = geometryFactory.createLinearRing(rings.get(0)); LinearRing[] inner = null; if (rings.size() > 1) { inner = new LinearRing[rings.size() - 1]; for (int i = 1; i < rings.size(); i++) { inner[i - 1] = geometryFactory.createLinearRing(rings.get(i)); } } polygons[p] = geometryFactory.createPolygon(outer, inner); ++p; } result = geometryFactory.createMultiPolygon(polygons); } catch (RuntimeException e) { throw new ParseException( "Could not parse MultiPolygon from GeoJson string.", e); } return result; }
Example 11
Source File: QuadEdgeTriangle.java From jts with GNU Lesser General Public License v2.1 | 4 votes |
public Polygon getGeometry(GeometryFactory fact) { LinearRing ring = fact.createLinearRing(getCoordinates()); Polygon tri = fact.createPolygon(ring, null); return tri; }