use of com.vividsolutions.jts.geom.Polygon in project ili2db by claeis.
the class Iox2fgdb method multisurface2wkb.
public byte[] multisurface2wkb(// SurfaceOrAreaType type)
IomObject multisurfaceObj, // SurfaceOrAreaType type)
boolean asCurvePolygon, // SurfaceOrAreaType type)
double strokeP, // SurfaceOrAreaType type)
int srsId) throws IoxException {
if (multisurfaceObj == null) {
return null;
}
byte[] ret = null;
os.reset();
if (asCurvePolygon) {
int shapeType = EsriShpConstants.ShapeGeneralPolygon;
shapeType |= EsriShpConstants.shapeHasCurves;
shapeType |= (outputDimension == 3 ? EsriShpConstants.shapeHasZs : 0);
os.writeInt(shapeType);
} else {
if (outputDimension == 3) {
os.writeInt(EsriShpConstants.ShapePolygonZ);
} else {
os.writeInt(EsriShpConstants.ShapePolygon);
}
}
java.util.ArrayList<Polygon> polygons = new java.util.ArrayList<Polygon>();
// boundingBox
Envelope env = new Envelope();
int surfacec = multisurfaceObj.getattrvaluecount("surface");
for (int surfacei = 0; surfacei < surfacec; surfacei++) {
IomObject surface = multisurfaceObj.getattrobj("surface", surfacei);
IomObject iomSurfaceClone = new ch.interlis.iom_j.Iom_jObject("MULTISURFACE", null);
iomSurfaceClone.addattrobj("surface", surface);
Polygon polygon = Iox2jtsext.surface2JTS(iomSurfaceClone, strokeP);
polygons.add(polygon);
env.expandToInclude(polygon.getEnvelopeInternal());
}
os.writeDouble(env.getMinX());
os.writeDouble(env.getMinY());
os.writeDouble(env.getMaxX());
os.writeDouble(env.getMaxY());
// cParts The number of rings in the multisurface.
// cPoints The total number of points for all parts.
int cPart = 0;
int cPoints = 0;
for (Polygon polygon : polygons) {
cPart += 1;
cPoints += getNumPoints(polygon.getExteriorRing());
int holec = polygon.getNumInteriorRing();
cPart += holec;
for (int holei = 0; holei < holec; holei++) {
cPoints += getNumPoints(polygon.getInteriorRingN(holei));
}
}
os.writeInt(cPart);
os.writeInt(cPoints);
// parts[cParts] An array of length NumParts. Stores, for each Ring, the index of its
// first point in the points array. Array indexes are with respect to 0.
int partStart = 0;
for (Polygon polygon : polygons) {
os.writeInt(partStart);
partStart += getNumPoints(polygon.getExteriorRing());
int holec = polygon.getNumInteriorRing();
for (int holei = 0; holei < holec; holei++) {
os.writeInt(partStart);
partStart += getNumPoints(polygon.getInteriorRingN(holei));
}
}
java.util.ArrayList<Arc> arcs = null;
if (asCurvePolygon) {
arcs = new java.util.ArrayList<Arc>();
}
java.util.ArrayList<Double> zv = null;
if (outputDimension == 3) {
zv = new java.util.ArrayList<Double>();
}
double[] zMin = new double[1];
double[] zMax = new double[1];
{
Coordinate coord = polygons.get(0).getExteriorRing().getStartPoint().getCoordinate();
if (outputDimension == 3) {
zMin[0] = coord.z;
zMax[0] = coord.z;
}
}
int startPtIdx = 0;
for (Polygon polygon : polygons) {
// shell is always in clockwise order
// holes are in a counterclockwise direction
LineString polyline = polygon.getExteriorRing();
polyline = asOneLine(polyline);
if (CGAlgorithms.isCCW(polyline.getCoordinates())) {
polyline = (LineString) polyline.reverse();
}
writePoints(polyline, false, zv, zMin, zMax, startPtIdx, arcs);
startPtIdx += getNumPoints(polyline);
int holec = polygon.getNumInteriorRing();
for (int holei = 0; holei < holec; holei++) {
polyline = polygon.getInteriorRingN(holei);
polyline = asOneLine(polyline);
if (!CGAlgorithms.isCCW(polyline.getCoordinates())) {
polyline = (LineString) polyline.reverse();
}
writePoints(polyline, true, zv, zMin, zMax, startPtIdx, arcs);
startPtIdx += getNumPoints(polyline);
}
}
if (outputDimension == 3) {
// zMin
os.writeDouble(zMin[0]);
// zMax
os.writeDouble(zMax[0]);
// Zs[cPoints]
for (Double z : zv) {
os.writeDouble(z);
}
}
if (asCurvePolygon) {
writeArcs(arcs);
}
ret = os.toByteArray();
return ret;
}
use of com.vividsolutions.jts.geom.Polygon in project ili2db by claeis.
the class Iox2gpkg method surface2wkb.
/**
* Converts a SURFACE to a JTS Polygon.
* @param obj INTERLIS SURFACE structure
* @param strokeP maximum stroke to use when removing ARCs
* @return JTS Polygon
* @throws Iox2wkbException
*/
public byte[] surface2wkb(// SurfaceOrAreaType type)
IomObject obj, // SurfaceOrAreaType type)
boolean asCurvePolygon, // SurfaceOrAreaType type)
double strokeP, // SurfaceOrAreaType type)
int srsId) throws Iox2wkbException {
if (obj == null) {
return null;
}
try {
os.reset();
Polygon surface = Iox2jtsext.surface2JTS(obj, strokeP);
writeGeoPackageBinaryHeader(srsId, surface.getEnvelopeInternal());
// wkb
Iox2wkb helper = new Iox2wkb(outputDimension, os.order());
os.write(helper.surface2wkb(obj, asCurvePolygon, strokeP));
} catch (IOException e) {
throw new RuntimeException("Unexpected IO exception: " + e.getMessage());
} catch (IoxException e) {
throw new RuntimeException("Unexpected exception: " + e.getMessage());
}
return os.toByteArray();
}
use of com.vividsolutions.jts.geom.Polygon in project tests by datanucleus.
the class JtsGeometrySpatialTest method testDifference.
@Datastore(POSTGRESQL)
public void testDifference() throws SQLException, ParseException {
PersistenceManager pm = pmf.getPersistenceManager();
Transaction tx = pm.currentTransaction();
try {
tx.begin();
Polygon polygon = (Polygon) wktReader.read("POLYGON((75 75,100 75,100 80,80 80,75 75))");
Polygon difference = (Polygon) wktReader.read("POLYGON((80 80,100 100,100 80,80 80))");
Query query = pm.newQuery(SamplePolygon.class, "geom != null && geom.difference(:polygon).equals(:difference)");
List list = (List) query.execute(polygon, difference);
assertEquals("Wrong number of geometries whose difference from a given polygon is equal to a given polygon returned", 1, list.size());
assertTrue("Polygon 2 should be in the list of geometries whose difference from a given polygon is equal to a given polygon", list.contains(getSamplePolygon(2)));
query = pm.newQuery(SamplePolygon.class, "id == :id");
query.setResult("geom.difference(Spatial.geomFromText('POLYGON((75 75,100 75,100 80,80 80,75 75))', 4326))");
query.setUnique(true);
Geometry difference_read = (Geometry) query.execute(new Long(getSamplePolygon(2).getId()));
difference.normalize();
difference_read.normalize();
assertTrue("Returned difference should be equal to the given polygon", difference_read.equalsExact(difference));
} finally {
tx.commit();
}
}
use of com.vividsolutions.jts.geom.Polygon in project openems by OpenEMS.
the class SVGWriter method appendGeometryTaggedText.
/**
* Converts a <code>Geometry</code> to <Geometry Tagged Text> format,
* then appends it to the writer.
*
* @param geometry
* the <code>Geometry</code> to process
* @param writer
* the output writer to append to
*/
private void appendGeometryTaggedText(Geometry geometry, int level, Writer writer) throws IOException {
indent(level, writer);
if (geometry instanceof Point) {
Point point = (Point) geometry;
appendPointTaggedText(point.getCoordinate(), level, writer, point.getPrecisionModel());
} else if (geometry instanceof LinearRing) {
appendLinearRingTaggedText((LinearRing) geometry, level, writer);
} else if (geometry instanceof LineString) {
appendLineStringTaggedText((LineString) geometry, level, writer);
} else if (geometry instanceof Polygon) {
appendPolygon((Polygon) geometry, level, writer);
} else if (geometry instanceof MultiPoint) {
appendMultiPointTaggedText((MultiPoint) geometry, level, writer);
} else if (geometry instanceof MultiLineString) {
appendMultiLineStringTaggedText((MultiLineString) geometry, level, writer);
} else if (geometry instanceof MultiPolygon) {
appendMultiPolygonTaggedText((MultiPolygon) geometry, level, writer);
} else if (geometry instanceof GeometryCollection) {
appendGeometryCollectionTaggedText((GeometryCollection) geometry, level, writer);
} else {
Assert.shouldNeverReachHere("Unsupported Geometry implementation:" + geometry.getClass());
}
}
use of com.vividsolutions.jts.geom.Polygon in project tests by datanucleus.
the class JtsGeometryMappingTest method testPolygonMapping.
public void testPolygonMapping() throws SQLException, ParseException {
if (!runTestsForDatastore()) {
return;
}
Polygon polygon = (Polygon) wktReader.read("POLYGON((25 25,75 25,75 75,25 75,25 25),(45 45,55 45,55 55,45 55,45 45))");
SamplePolygon samplePolygon;
SamplePolygon samplePolygon_read;
PersistenceManager pm = pmf.getPersistenceManager();
Transaction tx = pm.currentTransaction();
Object id = null;
try {
tx.begin();
samplePolygon = new SamplePolygon(3001, "Polygon 1", polygon);
pm.makePersistent(samplePolygon);
id = JDOHelper.getObjectId(samplePolygon);
samplePolygon = (SamplePolygon) pm.detachCopy(samplePolygon);
tx.commit();
} finally {
if (tx.isActive()) {
tx.rollback();
}
pm.close();
}
pm = pmf.getPersistenceManager();
tx = pm.currentTransaction();
try {
tx.begin();
samplePolygon_read = (SamplePolygon) pm.getObjectById(id, true);
assertEquals(samplePolygon, samplePolygon_read);
tx.commit();
} finally {
if (tx.isActive()) {
tx.rollback();
}
pm.close();
}
}
Aggregations