org.locationtech.jts.geom.MultiPoint Java Examples
The following examples show how to use
org.locationtech.jts.geom.MultiPoint.
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: GeometryTranslator.java From hortonmachine with GNU General Public License v3.0 | 6 votes |
/** * Builds a point feature from a dwg point. */ public SimpleFeature convertDwgPoint( String typeName, String layerName, DwgPoint point, int id ) { double[] p = point.getPoint(); Point2D pto = new Point2D.Double(p[0], p[1]); CoordinateList coordList = new CoordinateList(); Coordinate coord = new Coordinate(pto.getX(), pto.getY(), 0.0); coordList.add(coord); SimpleFeatureTypeBuilder b = new SimpleFeatureTypeBuilder(); b.setName(typeName); b.setCRS(crs); b.add(THE_GEOM, MultiPoint.class); b.add(LAYER, String.class); SimpleFeatureType type = b.buildFeatureType(); SimpleFeatureBuilder builder = new SimpleFeatureBuilder(type); Geometry points = gF.createMultiPoint(coordList.toCoordinateArray()); Object[] values = new Object[]{points, layerName}; builder.addAll(values); return builder.buildFeature(typeName + "." + id); }
Example #2
Source File: ShapeWriter.java From geopaparazzi with GNU General Public License v3.0 | 6 votes |
/** * Creates a {@link Shape} representing a {@link Geometry}, * according to the specified PointTransformation * and PointShapeFactory (if relevant). * <p> * Note that Shapes do not * preserve information fragment_about which elements in heterogeneous collections * are 1D and which are 2D. * For example, a GeometryCollection containing a ring and a * disk will render as two disks if Graphics.fill is used, * or as two rings if Graphics.draw is used. * To avoid this issue use separate shapes for the components. * * @param geometry the geometry to convert * @return a Shape representing the geometry */ public DrawableShape toShape(Geometry geometry) { if (geometry.isEmpty()) return new PathShape(new Path()); else if (geometry instanceof Polygon) return toShape((Polygon) geometry); else if (geometry instanceof MultiPolygon) return toShape((MultiPolygon) geometry); else if (geometry instanceof LineString) return toShape((LineString) geometry); else if (geometry instanceof MultiLineString) return toShape((MultiLineString) geometry); else if (geometry instanceof Point) return toShape((Point) geometry); else if (geometry instanceof MultiPoint) return toShape((MultiPoint) geometry); else if (geometry instanceof GeometryCollection) return toShape((GeometryCollection) geometry); throw new IllegalArgumentException("Unrecognized Geometry class: " + geometry.getClass()); }
Example #3
Source File: GeoJSONEncoder.java From arctic-sea with Apache License 2.0 | 6 votes |
protected ObjectNode encodeGeometry(Geometry geometry, int parentSrid) throws JSONEncodingException { Preconditions.checkNotNull(geometry); if (geometry.isEmpty()) { return null; } else if (geometry instanceof Point) { return encode((Point) geometry, parentSrid); } else if (geometry instanceof LineString) { return encode((LineString) geometry, parentSrid); } else if (geometry instanceof Polygon) { return encode((Polygon) geometry, parentSrid); } else if (geometry instanceof MultiPoint) { return encode((MultiPoint) geometry, parentSrid); } else if (geometry instanceof MultiLineString) { return encode((MultiLineString) geometry, parentSrid); } else if (geometry instanceof MultiPolygon) { return encode((MultiPolygon) geometry, parentSrid); } else if (geometry instanceof GeometryCollection) { return encode((GeometryCollection) geometry, parentSrid); } else { throw new JSONEncodingException("unknown geometry type " + geometry.getGeometryType()); } }
Example #4
Source File: SpatialiteWKBWriter.java From hortonmachine with GNU General Public License v3.0 | 6 votes |
public void write( Geometry geom, OutStream os ) throws IOException { buf[0] = 0x69; os.write(buf, 1); if (geom instanceof Point) writePoint((Point) geom, os); // LinearRings will be written as LineStrings else if (geom instanceof LineString) writeLineString((LineString) geom, os); else if (geom instanceof Polygon) writePolygon((Polygon) geom, os); else if (geom instanceof MultiPoint) writeGeometryCollection(WKBConstants.wkbMultiPoint, (MultiPoint) geom, os); else if (geom instanceof MultiLineString) writeGeometryCollection(WKBConstants.wkbMultiLineString, (MultiLineString) geom, os); else if (geom instanceof MultiPolygon) writeGeometryCollection(WKBConstants.wkbMultiPolygon, (MultiPolygon) geom, os); else if (geom instanceof GeometryCollection) writeGeometryCollection(WKBConstants.wkbGeometryCollection, (GeometryCollection) geom, os); else { Assert.shouldNeverReachHere("Unknown Geometry type"); } }
Example #5
Source File: TWKBWriter.java From geowave with Apache License 2.0 | 6 votes |
private byte getType(final Geometry geom) { if (geom instanceof Point) { return TWKBUtils.POINT_TYPE; } else if (geom instanceof LineString) { return TWKBUtils.LINESTRING_TYPE; } else if (geom instanceof Polygon) { return TWKBUtils.POLYGON_TYPE; } else if (geom instanceof MultiPoint) { return TWKBUtils.MULTIPOINT_TYPE; } else if (geom instanceof MultiLineString) { return TWKBUtils.MULTILINESTRING_TYPE; } else if (geom instanceof MultiPolygon) { return TWKBUtils.MULTIPOLYGON_TYPE; } return TWKBUtils.GEOMETRYCOLLECTION_TYPE; }
Example #6
Source File: GeoWaveSpatialEncoders.java From geowave with Apache License 2.0 | 6 votes |
public static void registerUDTs() { UDTRegistration.register( Geometry.class.getCanonicalName(), GeometryUDT.class.getCanonicalName()); UDTRegistration.register(Point.class.getCanonicalName(), PointUDT.class.getCanonicalName()); UDTRegistration.register( LineString.class.getCanonicalName(), LineStringUDT.class.getCanonicalName()); UDTRegistration.register(Polygon.class.getCanonicalName(), PolygonUDT.class.getCanonicalName()); UDTRegistration.register( MultiLineString.class.getCanonicalName(), MultiLineStringUDT.class.getCanonicalName()); UDTRegistration.register( MultiPoint.class.getCanonicalName(), MultiPointUDT.class.getCanonicalName()); UDTRegistration.register( MultiPolygon.class.getCanonicalName(), MultiPolygonUDT.class.getCanonicalName()); }
Example #7
Source File: VectorTileEncoder.java From java-vector-tile with Apache License 2.0 | 6 votes |
static VectorTile.Tile.GeomType toGeomType(Geometry geometry) { if (geometry instanceof Point) { return VectorTile.Tile.GeomType.POINT; } if (geometry instanceof MultiPoint) { return VectorTile.Tile.GeomType.POINT; } if (geometry instanceof LineString) { return VectorTile.Tile.GeomType.LINESTRING; } if (geometry instanceof MultiLineString) { return VectorTile.Tile.GeomType.LINESTRING; } if (geometry instanceof Polygon) { return VectorTile.Tile.GeomType.POLYGON; } if (geometry instanceof MultiPolygon) { return VectorTile.Tile.GeomType.POLYGON; } return VectorTile.Tile.GeomType.UNKNOWN; }
Example #8
Source File: RandomGeometryBuilder.java From elasticgeo with GNU General Public License v3.0 | 5 votes |
public MultiPoint createRandomMultiPoint() { Point[] points = new Point[numGeometries]; for (int i=0; i<numGeometries; i++) { points[i] = createRandomPoint(); } return geometryFactory.createMultiPoint(points); }
Example #9
Source File: JtsGeometrySerde.java From presto with Apache License 2.0 | 5 votes |
private static void writeMultiPoint(MultiPoint geometry, SliceOutput output) { output.writeByte(GeometrySerializationType.MULTI_POINT.code()); output.writeInt(EsriShapeType.MULTI_POINT.code); writeEnvelope(geometry, output); output.writeInt(geometry.getNumPoints()); for (Coordinate coordinate : geometry.getCoordinates()) { writeCoordinate(coordinate, output); } }
Example #10
Source File: TestVectorReshaper.java From hortonmachine with GNU General Public License v3.0 | 5 votes |
public void testConvexHull() throws Exception { String cql = "the_geom=convexHull(the_geom)"; GeometryFactory gf = GeometryUtilities.gf(); MultiPoint multiPoint = gf.createMultiPoint(new Coordinate[]{// HMTestMaps.getWestNorth(), HMTestMaps.getEastSouth(), HMTestMaps.getEastNorth()}); SimpleFeatureTypeBuilder b = new SimpleFeatureTypeBuilder(); b.setName("test"); b.setCRS(HMTestMaps.getCrs()); b.add("the_geom", MultiPoint.class); SimpleFeatureType type = b.buildFeatureType(); SimpleFeatureBuilder builder = new SimpleFeatureBuilder(type); Object[] values = new Object[]{multiPoint}; builder.addAll(values); SimpleFeature feature = builder.buildFeature(null); DefaultFeatureCollection newCollection = new DefaultFeatureCollection(); newCollection.add(feature); OmsVectorReshaper reshaper = new OmsVectorReshaper(); reshaper.inVector = newCollection; reshaper.pCql = cql; reshaper.process(); SimpleFeatureCollection outFC = reshaper.outVector; FeatureIterator<SimpleFeature> featureIterator = outFC.features(); SimpleFeature newFeature = featureIterator.next(); Geometry geometry = (Geometry) newFeature.getDefaultGeometry(); String geometryType = geometry.getGeometryType(); assertTrue(geometryType.toUpperCase().equals("POLYGON")); featureIterator.close(); }
Example #11
Source File: SpatialiteWKBReader.java From hortonmachine with GNU General Public License v3.0 | 5 votes |
private MultiPoint readMultiPoint() throws IOException, ParseException { int numGeom = dis.readInt(); Point[] geoms = new Point[numGeom]; for( int i = 0; i < numGeom; i++ ) { Geometry g = readGeometry(); if (!(g instanceof Point)) throw new ParseException(INVALID_GEOM_TYPE_MSG + "MultiPoint"); geoms[i] = (Point) g; } return factory.createMultiPoint(geoms); }
Example #12
Source File: VectorTileEncoder.java From java-vector-tile with Apache License 2.0 | 5 votes |
List<Integer> commands(Geometry geometry) { if (geometry instanceof MultiLineString) { return commands((MultiLineString) geometry); } if (geometry instanceof Polygon) { return commands((Polygon) geometry); } if (geometry instanceof MultiPolygon) { return commands((MultiPolygon) geometry); } return commands(geometry.getCoordinates(), shouldClosePath(geometry), geometry instanceof MultiPoint); }
Example #13
Source File: TWKBReader.java From geowave with Apache License 2.0 | 5 votes |
private MultiPoint readMultiPoint( final PrecisionReader precision, final byte metadata, final ByteBuffer input) throws IOException { if ((metadata & TWKBUtils.EMPTY_GEOMETRY) != 0) { return GeometryUtils.GEOMETRY_FACTORY.createMultiPoint(); } final Coordinate[] points = precision.readPointArray(input); return GeometryUtils.GEOMETRY_FACTORY.createMultiPointFromCoords(points); }
Example #14
Source File: GeometryTransform.java From sis with Apache License 2.0 | 5 votes |
/** * Transforms the given geometry. This method delegates to one of the {@code transform(…)} methods * based on the type of the given geometry. * * @param geom the geometry to transform. * @return the transformed geometry. * @throws TransformException if an error occurred while transforming the geometry. */ public Geometry transform(final Geometry geom) throws TransformException { if (geom instanceof Point) return transform((Point) geom); if (geom instanceof MultiPoint) return transform((MultiPoint) geom); if (geom instanceof LinearRing) return transform((LinearRing) geom); // Must be tested before LineString. if (geom instanceof LineString) return transform((LineString) geom); if (geom instanceof MultiLineString) return transform((MultiLineString) geom); if (geom instanceof Polygon) return transform((Polygon) geom); if (geom instanceof MultiPolygon) return transform((MultiPolygon) geom); if (geom instanceof GeometryCollection) return transform((GeometryCollection) geom); throw new IllegalArgumentException(Errors.format(Errors.Keys.UnsupportedType_1, Classes.getClass(geom))); }
Example #15
Source File: GeoJSONUtils.java From crate with Apache License 2.0 | 5 votes |
public Map<String, Object> convert(Geometry geometry) { HashMap<String, Object> builder = new HashMap<>(); if (geometry instanceof Point) { builder.put(TYPE_FIELD, POINT); builder.put(COORDINATES_FIELD, extract((Point) geometry)); } else if (geometry instanceof MultiPoint) { builder.put(TYPE_FIELD, MULTI_POINT); builder.put(COORDINATES_FIELD, extract((MultiPoint) geometry)); } else if (geometry instanceof LineString) { builder.put(TYPE_FIELD, LINE_STRING); builder.put(COORDINATES_FIELD, extract((LineString) geometry)); } else if (geometry instanceof MultiLineString) { builder.put(TYPE_FIELD, MULTI_LINE_STRING); builder.put(COORDINATES_FIELD, extract((MultiLineString) geometry)); } else if (geometry instanceof Polygon) { builder.put(TYPE_FIELD, POLYGON); builder.put(COORDINATES_FIELD, extract((Polygon) geometry)); } else if (geometry instanceof MultiPolygon) { builder.put(TYPE_FIELD, MULTI_POLYGON); builder.put(COORDINATES_FIELD, extract((MultiPolygon) geometry)); } else if (geometry instanceof GeometryCollection) { GeometryCollection geometryCollection = (GeometryCollection) geometry; int size = geometryCollection.getNumGeometries(); List<Map<String, Object>> geometries = new ArrayList<>(size); for (int i = 0; i < size; i++) { geometries.add(convert(geometryCollection.getGeometryN(i))); } builder.put(TYPE_FIELD, GEOMETRY_COLLECTION); builder.put(GEOMETRIES_FIELD, geometries); } else { throw new IllegalArgumentException(String.format(Locale.ENGLISH, "Cannot extract coordinates from geometry %s", geometry.getGeometryType())); } return Collections.unmodifiableMap(builder); }
Example #16
Source File: ShapeWriter.java From geopaparazzi with GNU General Public License v3.0 | 5 votes |
private DrawableShape toShape(MultiPoint points) { GeometryCollectionShape shapes = new GeometryCollectionShape(); int numGeometries = points.getNumGeometries(); for (int i = 0; i < numGeometries; i++) { Point point = (Point) points.getGeometryN(i); PointF viewPoint = transformPoint(point.getCoordinate()); DrawableShape drawableShape = pointFactory.createPoint(viewPoint); shapes.add(drawableShape); } return shapes; }
Example #17
Source File: JtsPointIterable.java From geogson with Apache License 2.0 | 5 votes |
public static JtsPointIterable of(final MultiPoint src) { return new JtsPointIterable(new PointProvider() { @Override public int getNumPoints() { return src.getNumGeometries(); } @Override public Point getPointN(int n) { return (Point) src.getGeometryN(n); } }); }
Example #18
Source File: JtsGeometrySerde.java From presto with Apache License 2.0 | 5 votes |
private static void writeGeometry(Geometry geometry, DynamicSliceOutput output) { switch (geometry.getGeometryType()) { case "Point": writePoint((Point) geometry, output); break; case "MultiPoint": writeMultiPoint((MultiPoint) geometry, output); break; case "LineString": writePolyline(geometry, output, false); break; case "MultiLineString": writePolyline(geometry, output, true); break; case "Polygon": writePolygon(geometry, output, false); break; case "MultiPolygon": writePolygon(geometry, output, true); break; case "GeometryCollection": writeGeometryCollection(geometry, output); break; default: throw new IllegalArgumentException("Unsupported geometry type : " + geometry.getGeometryType()); } }
Example #19
Source File: JTSHelper.java From arctic-sea with Apache License 2.0 | 5 votes |
public Geometry convertSequence(Geometry geometry) { if (geometry instanceof Point) { return createPoint(((Point) geometry).getCoordinateSequence()); } else if (geometry instanceof LinearRing) { return createLinearRing(((LinearRing) geometry).getCoordinates()); } else if (geometry instanceof LineString) { return createLineString(((LineString) geometry).getCoordinates()); } else if (geometry instanceof Polygon) { LinearRing[] linearRings = new LinearRing[((Polygon) geometry).getNumInteriorRing()]; for (int i = 0; i < ((Polygon) geometry).getNumInteriorRing(); i++) { linearRings[i] = (LinearRing) convertSequence(((Polygon) geometry).getInteriorRingN(i)); } return createPolygon((LinearRing) convertSequence(((Polygon) geometry).getExteriorRing()), linearRings); } else if (geometry instanceof MultiPoint) { return createMultiPointFromCoords(((MultiPoint) geometry).getCoordinates()); } else if (geometry instanceof MultiLineString) { LineString[] lineStrings = new LineString[((MultiLineString) geometry).getNumGeometries()]; for (int i = 0; i < ((MultiLineString) geometry).getNumGeometries(); i++) { lineStrings[i] = (LineString) convertSequence(((MultiLineString) geometry).getGeometryN(i)); } return createMultiLineString(lineStrings); } else if (geometry instanceof MultiPolygon) { Polygon[] polygons = new Polygon[((MultiPolygon) geometry).getNumGeometries()]; for (int i = 0; i < ((MultiPolygon) geometry).getNumGeometries(); i++) { polygons[i] = (Polygon) convertSequence(((MultiPolygon) geometry).getGeometryN(i)); } return createMultiPolygon(polygons); } else if (geometry instanceof GeometryCollection) { Geometry[] geometries = new Geometry[((GeometryCollection) geometry).getNumGeometries()]; for (int i = 0; i < ((GeometryCollection) geometry).getNumGeometries(); i++) { geometries[i] = convertSequence(((GeometryCollection) geometry).getGeometryN(i)); } return createGeometryCollection(geometries); } return geometry; }
Example #20
Source File: GeometryTypeMapping.java From sldeditor with GNU General Public License v3.0 | 5 votes |
/** Populate member data. */ private static void populate() { geometryMap.put(Point.class, GeometryTypeEnum.POINT); geometryMap.put(MultiPoint.class, GeometryTypeEnum.POINT); geometryMap.put(LineString.class, GeometryTypeEnum.LINE); geometryMap.put(MultiLineString.class, GeometryTypeEnum.LINE); geometryMap.put(Polygon.class, GeometryTypeEnum.POLYGON); geometryMap.put(MultiPolygon.class, GeometryTypeEnum.POLYGON); geometryMap.put(GridCoverage2D.class, GeometryTypeEnum.RASTER); }
Example #21
Source File: AbstractMultiPointCoverageTypeEncoder.java From arctic-sea with Apache License 2.0 | 5 votes |
private void encodeMultiPointDomain(DiscreteCoverageType dct, PointValueLists pointValues) throws EncodingException { MultiPointDomainDocument mpdd = MultiPointDomainDocument.Factory.newInstance(); DomainSetType mpdst = mpdd.addNewMultiPointDomain(); GeometryFactory factory = pointValues.getPoints().get(0).getFactory(); MultiPoint multiPoint = factory.createMultiPoint(pointValues.getPoints().toArray(new Point[0])); EncodingContext ec = EncodingContext.of(XmlBeansEncodingFlags.GMLID, IdGenerator.generate(multiPoint.toString())) .with(XmlBeansEncodingFlags.PROPERTY_TYPE, true); XmlObject encodedGeometry = encodeGML(multiPoint, ec); mpdst.addNewAbstractGeometry().set(encodedGeometry); substitute(mpdst.getAbstractGeometry(), encodedGeometry); dct.setDomainSet(mpdst); }
Example #22
Source File: GmlEncoderv321.java From arctic-sea with Apache License 2.0 | 5 votes |
private void createMultiPointFromJtsGeometry(MultiPoint geom, MultiPointType xbMultiPoint, String id) throws EncodingException { for (int i = 0; i < geom.getNumGeometries(); i++) { Geometry geometry = geom.getGeometryN(i); if (geometry instanceof Point) { PointType pt = xbMultiPoint.addNewPointMember().addNewPoint(); pt.setId(id + "_" + i); createPointFromJtsGeometry((Point) geometry, pt); } } }
Example #23
Source File: SamplingEncoderv20.java From arctic-sea with Apache License 2.0 | 5 votes |
private String getFeatureType(Geometry geometry) { if (geometry instanceof Point || geometry instanceof MultiPoint) { return SfConstants.SAMPLING_FEAT_TYPE_SF_SAMPLING_POINT; } else if (geometry instanceof LineString || geometry instanceof MultiLineString) { return SfConstants.SAMPLING_FEAT_TYPE_SF_SAMPLING_CURVE; } else if (geometry instanceof Polygon || geometry instanceof MultiPolygon) { return SfConstants.SAMPLING_FEAT_TYPE_SF_SAMPLING_SURFACE; } else { return SfConstants.SAMPLING_FEAT_TYPE_SF_SAMPLING_FEATURE; } }
Example #24
Source File: SamplingDecoderv20.java From arctic-sea with Apache License 2.0 | 5 votes |
private String getFeatTypeForGeometry(final Geometry geometry) { if (geometry instanceof Point || geometry instanceof MultiPoint) { return SfConstants.SAMPLING_FEAT_TYPE_SF_SAMPLING_POINT; } else if (geometry instanceof LineString || geometry instanceof MultiLineString) { return SfConstants.SAMPLING_FEAT_TYPE_SF_SAMPLING_CURVE; } else if (geometry instanceof Polygon || geometry instanceof MultiPolygon) { return SfConstants.SAMPLING_FEAT_TYPE_SF_SAMPLING_SURFACE; } return SfConstants.SAMPLING_FEAT_TYPE_SF_SAMPLING_FEATURE; }
Example #25
Source File: GeoJSONEncoder.java From arctic-sea with Apache License 2.0 | 5 votes |
protected ObjectNode encode(MultiPoint geometry, int parentSrid) { Preconditions.checkNotNull(geometry); ObjectNode json = jsonFactory.objectNode(); ArrayNode list = json.put(JSONConstants.TYPE, JSONConstants.MULTI_POINT).putArray(JSONConstants.COORDINATES); for (int i = 0; i < geometry.getNumGeometries(); ++i) { list.add(encodeCoordinates((Point) geometry.getGeometryN(i))); } encodeCRS(json, geometry, parentSrid); return json; }
Example #26
Source File: GeoJSONTest.java From arctic-sea with Apache License 2.0 | 5 votes |
@Test public void testMultiPointWithZCoordinate() { MultiPoint geometry = randomMultiPoint(EPSG_4326); geometry.apply(new RandomZCoordinateFilter()); geometry.geometryChanged(); readWriteTest(geometry); }
Example #27
Source File: TWKBWriter.java From geowave with Apache License 2.0 | 4 votes |
private void writeMultiPoint( final MultiPoint multiPoint, final PrecisionWriter precision, final DataOutput output) throws IOException { precision.writePointArray(multiPoint.getCoordinates(), output); }
Example #28
Source File: JTSHelper.java From arctic-sea with Apache License 2.0 | 4 votes |
@Override public MultiPoint createMultiPoint(CoordinateSequence coordinates) { return super.createMultiPoint(convert(coordinates)); }
Example #29
Source File: GeoJSONUtils.java From crate with Apache License 2.0 | 4 votes |
private double[][] extract(MultiPoint multiPoint) { return toArray(multiPoint.getCoordinates()); }
Example #30
Source File: GeoJSONDecoder.java From arctic-sea with Apache License 2.0 | 4 votes |
protected MultiPoint decodeMultiPoint(JsonNode node, GeometryFactory fac) throws GeoJSONDecodingException { Coordinate[] coordinates = decodeCoordinates(requireCoordinates(node)); return fac.createMultiPointFromCoords(coordinates); }