本文整理汇总了Java中org.postgis.Polygon类的典型用法代码示例。如果您正苦于以下问题:Java Polygon类的具体用法?Java Polygon怎么用?Java Polygon使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Polygon类属于org.postgis包,在下文中一共展示了Polygon类的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: reverseMap
import org.postgis.Polygon; //导入依赖的package包/类
@Override
public Map<String, Object> reverseMap(List<LatLng> latLngs, Action action) {
Point[] points = new Point[latLngs.size() + 1]; //+1 to close the ring
List<LatLng> path = latLngs;
for (int i = 0; i < path.size(); i++) {
LatLng latLng = path.get(i);
points[i] = new Point(latLng.getLng(), latLng.getLat());
}
//close the ring
points[points.length - 1] = points[0];
Polygon polygon = new Polygon(new LinearRing[]{new LinearRing(points)});
polygon.setSrid(Mappers.WGS84_SRID);
Map<String, Object> params = new HashMap<>(1);
params.put(colName, new PGgeometry(polygon));
return params;
}
示例2: testBulkWithinPolygon
import org.postgis.Polygon; //导入依赖的package包/类
@Test
public void testBulkWithinPolygon() throws SQLException {
LinearRing linearRing1 = new LinearRing("0 0, 1 1, 1 2, 1 1, 0 0");
Polygon polygon1 = new Polygon(new LinearRing[]{linearRing1});
LinearRing linearRing2 = new LinearRing("1 1, 1 1, 1 2, 1 1, 1 1");
Polygon polygon2 = new Polygon(new LinearRing[]{linearRing2});
LinearRing linearRing3 = new LinearRing("2 2, 1 1, 1 2, 1 1, 2 2");
Polygon polygon3 = new Polygon(new LinearRing[]{linearRing3});
LinearRing linearRing4 = new LinearRing("1 3, 1 2, 2 2, 1 1, 1 3");
Polygon polygon4 = new Polygon(new LinearRing[]{linearRing4});
Vertex v1 = this.sqlgGraph.addVertex(T.label, "Gis", "polygon", polygon1);
Vertex v2 = this.sqlgGraph.addVertex(T.label, "Gis", "polygon", polygon2);
Vertex v3 = this.sqlgGraph.addVertex(T.label, "Gis", "polygon", polygon3);
Vertex v4 = this.sqlgGraph.addVertex(T.label, "Gis", "polygon", polygon4);
this.sqlgGraph.tx().commit();
List<Vertex> vertices = this.sqlgGraph.traversal().V().hasLabel("Gis").has("polygon", P.within(polygon1, polygon3, polygon4)).toList();
Assert.assertEquals(3, vertices.size());
Assert.assertTrue(Arrays.asList(v1, v3, v4).containsAll(vertices));
}
示例3: getMultiPolygon
import org.postgis.Polygon; //导入依赖的package包/类
@Override
public GeometryObject getMultiPolygon(Object geomObj) throws SQLException {
GeometryObject multiPolygon = null;
if (geomObj instanceof PGgeometry) {
Geometry geometry = ((PGgeometry)geomObj).getGeometry();
if (geometry.getType() == Geometry.MULTIPOLYGON) {
multiPolygon = getMultiPolygon((MultiPolygon)geometry);
}
else if (geometry.getType() == Geometry.POLYGON) {
Polygon polygonObj = (Polygon)geometry;
double[][] coordinates = getPolygonCoordinates(polygonObj);
int[] exteriorRings = new int[]{ 0 };
multiPolygon = GeometryObject.createMultiPolygon(coordinates, exteriorRings, polygonObj.getDimension(), polygonObj.getSrid());
}
}
return multiPolygon;
}
示例4: getGeometry
import org.postgis.Polygon; //导入依赖的package包/类
@Override
public GeometryObject getGeometry(Object geomObj) throws SQLException {
if (geomObj instanceof PGgeometry) {
Geometry geometry = ((PGgeometry)geomObj).getGeometry();
switch (geometry.getType()) {
case Geometry.POINT:
return getPoint((Point)geometry);
case Geometry.MULTIPOINT:
return getMultiPoint((MultiPoint)geometry);
case Geometry.LINESTRING:
return getCurve((LineString)geometry);
case Geometry.MULTILINESTRING:
return getMultiCurve((MultiLineString)geometry);
case Geometry.POLYGON:
return getPolygon((Polygon)geometry);
case Geometry.MULTIPOLYGON:
return getMultiPolygon((MultiPolygon)geometry);
default:
throw new SQLException("Cannot convert PostGIS geometry type '" + geometry.getType() + "' to internal representation: Unsupported type.");
}
}
return null;
}
示例5: before
import org.postgis.Polygon; //导入依赖的package包/类
@Before
public void before() {
table = "test_polygon";
Point[] points = new Point[5];
points[0] = new Point(123.45d, 23.45d);
points[1] = new Point(124.45d, 23.45d);
points[2] = new Point(124.45d, 24.45d);
points[3] = new Point(123.45d, 24.45d);
points[4] = new Point(123.45d, 23.45d);
LinearRing linearRing = new LinearRing(points);
t = new Polygon(new LinearRing[]{linearRing});
t.setSrid(SRID);
}
示例6: mapRow
import org.postgis.Polygon; //导入依赖的package包/类
@Override
public List<LatLng> mapRow(ResultSet rs, int rowNum) throws SQLException {
PGgeometry pggeom = (PGgeometry) rs.getObject(colName);
Polygon polygon = (Polygon) pggeom.getGeometry();
List<LatLng> path = new ArrayList<>(polygon.getRing(0).getPoints().length);
Point[] points = polygon.getRing(0).getPoints();
for (int i = 0; i < points.length - 1; i++) {
Point p = points[i];
path.add(new LatLng(p.getY(), p.getX()));
}
return path;
}
示例7: GeographyPolygon
import org.postgis.Polygon; //导入依赖的package包/类
public GeographyPolygon(Polygon polygon) {
this.polygon = polygon;
this.srid = polygon.srid;
this.haveMeasure = polygon.haveMeasure;
this.dimension = polygon.dimension;
this.subgeoms = new Geometry[polygon.numGeoms()];
for (int i = 0 ; i < polygon.numGeoms(); i++) {
subgeoms[i] = polygon.getSubGeometry(i);
}
}
示例8: getPolygon
import org.postgis.Polygon; //导入依赖的package包/类
@Override
public GeometryObject getPolygon(Object geomObj) throws SQLException {
GeometryObject polygon = null;
if (geomObj instanceof PGgeometry) {
Geometry geometry = ((PGgeometry)geomObj).getGeometry();
if (geometry.getType() != Geometry.POLYGON)
return null;
polygon = getPolygon((Polygon)geometry);
}
return polygon;
}
示例9: getTypeHandler
import org.postgis.Polygon; //导入依赖的package包/类
@Override
protected TypeHandler<Polygon> getTypeHandler() {
return TYPE_HANDLER;
}
示例10: createPlacemarksForLoD0Network
import org.postgis.Polygon; //导入依赖的package包/类
private List<PlacemarkType> createPlacemarksForLoD0Network(ResultSet rs,
KmlSplittingResult work) throws SQLException {
DisplayForm footprintSettings = new DisplayForm(DisplayForm.FOOTPRINT, -1, -1);
int indexOfDf = getDisplayForms().indexOf(footprintSettings);
if (indexOfDf != -1) {
footprintSettings = getDisplayForms().get(indexOfDf);
}
List<PlacemarkType> placemarkList= new ArrayList<PlacemarkType>();
while (rs.next()) {
PlacemarkType placemark = kmlFactory.createPlacemarkType();
placemark.setName(work.getGmlId() + "_Transportation_Network");
placemark.setId(/* DisplayForm.FOOTPRINT_PLACEMARK_ID + */ placemark.getName());
if (footprintSettings.isHighlightingEnabled())
placemark.setStyleUrl("#" + getStyleBasisName() + DisplayForm.FOOTPRINT_STR + "Style");
else
placemark.setStyleUrl("#" + getStyleBasisName() + DisplayForm.FOOTPRINT_STR + "Normal");
PGgeometry pgBuildingGeometry = (PGgeometry)rs.getObject(1);
Polygon pointOrCurveGeometry = (Polygon)super.convertToWGS84(pgBuildingGeometry.getGeometry());
double[] ordinatesArray = new double[pointOrCurveGeometry.numPoints()*3];
for (int i = 0, j = 0; i < pointOrCurveGeometry.numPoints(); i++, j+=3){
ordinatesArray[j] = pointOrCurveGeometry.getPoint(i).x;
ordinatesArray[j+1] = pointOrCurveGeometry.getPoint(i).y;
ordinatesArray[j+2] = pointOrCurveGeometry.getPoint(i).z;
}
eventDispatcher.triggerEvent(new GeometryCounterEvent(null, this));
if (ordinatesArray.length == 3) { // point
PointType point = kmlFactory.createPointType();
point.getCoordinates().add(String.valueOf(reducePrecisionForXorY(ordinatesArray[0]) + ","
+ reducePrecisionForXorY(ordinatesArray[1]) + ","
+ reducePrecisionForZ(ordinatesArray[2])));
placemark.setAbstractGeometryGroup(kmlFactory.createPoint(point));
}
else { // curve
LineStringType lineString = kmlFactory.createLineStringType();
int cellCount = 0;
for (int i = 0; i < pointOrCurveGeometry.numRings(); i++){
int startNextRing = ((i+1) < pointOrCurveGeometry.numRings()) ?
(pointOrCurveGeometry.getRing(i).numPoints()*3): // still holes to come
ordinatesArray.length; // default
// order points clockwise
for (int j = cellCount; j < startNextRing; j+=3) {
lineString.getCoordinates().add(String.valueOf(reducePrecisionForXorY(ordinatesArray[j]) + ","
+ reducePrecisionForXorY(ordinatesArray[j+1]) + ","
+ reducePrecisionForZ(ordinatesArray[j+2])));
}
cellCount += (pointOrCurveGeometry.getRing(i).numPoints()*3);
}
lineString.setAltitudeModeGroup(kmlFactory.createAltitudeMode(AltitudeModeEnumType.CLAMP_TO_GROUND));
placemark.setAbstractGeometryGroup(kmlFactory.createLineString(lineString));
}
// replace default BalloonTemplateHandler with a brand new one, this costs resources!
if (getBalloonSettings().isIncludeDescription()) {
addBalloonContents(placemark, work.getId());
}
placemarkList.add(placemark);
}
return placemarkList;
}