use of org.locationtech.jts.geom.Polygon in project presto by prestodb.
the class JtsGeometrySerde method writePolygon.
private static void writePolygon(Geometry geometry, SliceOutput output, boolean multitype) {
int numGeometries = geometry.getNumGeometries();
int numParts = 0;
int numPoints = geometry.getNumPoints();
for (int i = 0; i < numGeometries; i++) {
Polygon polygon = (Polygon) geometry.getGeometryN(i);
if (polygon.getNumPoints() > 0) {
numParts += polygon.getNumInteriorRing() + 1;
}
}
if (multitype) {
output.writeByte(GeometrySerializationType.MULTI_POLYGON.code());
} else {
output.writeByte(GeometrySerializationType.POLYGON.code());
}
output.writeInt(EsriShapeType.POLYGON.code);
writeEnvelope(geometry, output);
output.writeInt(numParts);
output.writeInt(numPoints);
if (numParts == 0) {
return;
}
int[] partIndexes = new int[numParts];
boolean[] shellPart = new boolean[numParts];
int currentPart = 0;
int currentPoint = 0;
for (int i = 0; i < numGeometries; i++) {
Polygon polygon = (Polygon) geometry.getGeometryN(i);
partIndexes[currentPart] = currentPoint;
shellPart[currentPart] = true;
currentPart++;
currentPoint += polygon.getExteriorRing().getNumPoints();
int holesCount = polygon.getNumInteriorRing();
for (int holeIndex = 0; holeIndex < holesCount; holeIndex++) {
partIndexes[currentPart] = currentPoint;
shellPart[currentPart] = false;
currentPart++;
currentPoint += polygon.getInteriorRingN(holeIndex).getNumPoints();
}
}
for (int partIndex : partIndexes) {
output.writeInt(partIndex);
}
Coordinate[] coordinates = geometry.getCoordinates();
canonicalizePolygonCoordinates(coordinates, partIndexes, shellPart);
writeCoordinates(coordinates, output);
}
use of org.locationtech.jts.geom.Polygon in project arctic-sea by 52North.
the class GmlDecoderv321 method parseCompositeSurfaceType.
private Geometry parseCompositeSurfaceType(CompositeSurfaceType xbCompositeSurface) throws DecodingException {
SurfacePropertyType[] xbCurfaceProperties = xbCompositeSurface.getSurfaceMemberArray();
int srid = -1;
ArrayList<Polygon> polygons = new ArrayList<>(xbCurfaceProperties.length);
if (xbCompositeSurface.getSrsName() != null) {
srid = CRSHelper.parseSrsName(xbCompositeSurface.getSrsName());
}
for (SurfacePropertyType xbSurfaceProperty : xbCurfaceProperties) {
AbstractSurfaceType xbAbstractSurface = xbSurfaceProperty.getAbstractSurface();
if (srid == -1 && xbAbstractSurface.getSrsName() != null) {
srid = CRSHelper.parseSrsName(xbAbstractSurface.getSrsName());
}
if (xbAbstractSurface instanceof PolygonType) {
polygons.add((Polygon) parsePolygonType((PolygonType) xbAbstractSurface));
} else {
throw new DecodingException("The FeatureType %s is not supportted! Only PolygonType", xbAbstractSurface);
}
}
if (polygons.isEmpty()) {
throw new DecodingException("The FeatureType: %s does not contain any member!", xbCompositeSurface);
}
srid = setDefaultForUnsetSrid(srid);
GeometryFactory factory = new GeometryFactory();
Geometry geom = factory.createMultiPolygon(polygons.toArray(new Polygon[polygons.size()]));
geom.setSRID(srid);
return geom;
}
use of org.locationtech.jts.geom.Polygon in project dhis2-core by dhis2.
the class GeoUtils method checkPointWithMultiPolygon.
/**
* Check if the point coordinate falls within the polygon/MultiPolygon Shape
*
* @param longitude the longitude.
* @param latitude the latitude.
* @param geometry the GeoJSON coordinates of the MultiPolygon
*/
public static boolean checkPointWithMultiPolygon(double longitude, double latitude, Geometry geometry) {
try {
boolean contains = false;
Point point = getGeoJsonPoint(longitude, latitude);
FeatureType featureType = FeatureType.getTypeFromName(geometry.getGeometryType());
if (point != null && point.isValid()) {
if (featureType == FeatureType.POLYGON) {
Polygon polygon = (Polygon) geometry;
contains = polygon.contains(point);
} else if (featureType == FeatureType.MULTI_POLYGON) {
MultiPolygon multiPolygon = (MultiPolygon) geometry;
contains = multiPolygon.contains(point);
}
}
return contains;
} catch (Exception ex) {
return false;
}
}
use of org.locationtech.jts.geom.Polygon in project yyl_example by Relucent.
the class JtsGeometryExample2 method withinGeo.
/**
* 判断以x,y为坐标的点point(x,y)是否在geometry表示的Polygon中
* @param x 坐标
* @param y 坐标
* @param 表达式
* @return 是否包含
*/
public static boolean withinGeo(double x, double y, String geometry) throws ParseException {
Coordinate coord = new Coordinate(x, y);
Point point = GEOMETRY_FACTORY.createPoint(coord);
WKTReader reader = new WKTReader(GEOMETRY_FACTORY);
Polygon polygon = (Polygon) reader.read(geometry);
return point.within(polygon);
}
use of org.locationtech.jts.geom.Polygon in project yyl_example by Relucent.
the class JtsGeometryExample1 method createGeoCollect.
/**
* create GeometryCollection contain point or multiPoint or line or multiLine or polygon or multiPolygon
* @return 图形集
* @throws ParseException
*/
public static GeometryCollection createGeoCollect() throws ParseException {
LineString line = createLine();
Polygon poly = createPolygonByWKT();
Geometry g1 = GEOMETRY_FACTORY.createGeometry(line);
Geometry g2 = GEOMETRY_FACTORY.createGeometry(poly);
Geometry[] garray = new Geometry[] { g1, g2 };
GeometryCollection gc = GEOMETRY_FACTORY.createGeometryCollection(garray);
return gc;
}
Aggregations