本文整理匯總了Java中com.vividsolutions.jts.geom.GeometryFactory類的典型用法代碼示例。如果您正苦於以下問題:Java GeometryFactory類的具體用法?Java GeometryFactory怎麽用?Java GeometryFactory使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
GeometryFactory類屬於com.vividsolutions.jts.geom包,在下文中一共展示了GeometryFactory類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: flatten
import com.vividsolutions.jts.geom.GeometryFactory; //導入依賴的package包/類
/** */
public static Geometry flatten (GeometryCollection gc) {
final List<Point> points = new LinkedList<Point>();
final List<LineString> lines = new LinkedList<LineString>();
final List<Polygon> polygons = new LinkedList<Polygon>();
gc.apply(new GeometryFilter() {
public void filter (Geometry geom) {
if (geom instanceof Point) {
points.add((Point)geom);
} else if (geom instanceof LineString) {
lines.add((LineString)geom);
} else if (geom instanceof Polygon) {
polygons.add((Polygon)geom);
}
}
});
if (!polygons.isEmpty()) {
return gc.getFactory().createMultiPolygon(GeometryFactory.toPolygonArray(polygons));
} else if (!lines.isEmpty()) {
return gc.getFactory().createMultiLineString(GeometryFactory.toLineStringArray(lines));
} else {
return gc.getFactory().createMultiPoint(GeometryFactory.toPointArray(points));
}
}
示例2: GeometryImage
import com.vividsolutions.jts.geom.GeometryFactory; //導入依賴的package包/類
/**
*
* @param name
* @param type
* @param geoms
*/
public GeometryImage(String name,String type,List<Coordinate>geoms) {
this.type=type;
this.name=name;
this.geoms=new ArrayList<>();
//attsMap=new HashMap<>();
GeometryFactory gf = new GeometryFactory();
for(Coordinate c:geoms){
AttributesGeometry att = new AttributesGeometry(new String[]{"x","y"});
att.set("x",c.x);
att.set("y",c.y);
Geometry gg=gf.createPoint(c);
put(gg, att);
}
}
示例3: getShape
import com.vividsolutions.jts.geom.GeometryFactory; //導入依賴的package包/類
public Area getShape() {
Area maskArea = new Area();
Rectangle rect = new Rectangle(0, 0, reader.getWidth(), reader.getHeight());
GeometryFactory gf = new GeometryFactory();
Coordinate[] coords = new Coordinate[]{
new Coordinate((int) rect.getMinX(), (int) rect.getMinY()),
new Coordinate((int) rect.getMaxX(), (int) rect.getMinY()),
new Coordinate((int) rect.getMaxX(), (int) rect.getMaxY()),
new Coordinate((int) rect.getMinX(), (int) rect.getMaxY()),
new Coordinate((int) rect.getMinX(), (int) rect.getMinY()),
};
Polygon geom = gf.createPolygon(gf.createLinearRing(coords), null);
for (Geometry p : glayer.getGeometries()) {
if (p.intersects(geom)) {
int[] xPoints = new int[p.getNumPoints()];
int[] yPoints = new int[p.getNumPoints()];
int i = 0;
for (Coordinate c : p.getCoordinates()) {
xPoints[i] = (int) (c.x);
yPoints[i++] = (int) (c.y);
}
maskArea.add(new Area(new java.awt.Polygon(xPoints, yPoints, p.getNumPoints())));
}
}
return maskArea;
}
示例4: checkIfTileIsOnLand
import com.vividsolutions.jts.geom.GeometryFactory; //導入依賴的package包/類
/**
* check if the tile is on land
*
* @param top
* @param left
* @param bottom
* @param right
* @return
*/
public boolean checkIfTileIsOnLand(double top,double left,double bottom,double right){
boolean isOnLand=false;
if(land!=null){
GeometryFactory fact = new GeometryFactory();
Coordinate[] cs=new Coordinate[5];
cs[0]=new Coordinate(top, left);
cs[1]=new Coordinate(bottom, left);
cs[2]=new Coordinate(top,right);
cs[3]=new Coordinate(bottom,right);
cs[4]=new Coordinate(top,left);
Polygon tile=fact.createPolygon(cs);
for (Geometry p : land) {
if (p.contains(tile)) {
isOnLand=true;
break;
}
}
}
return isOnLand;
}
示例5: contains
import com.vividsolutions.jts.geom.GeometryFactory; //導入依賴的package包/類
public boolean contains(int x, int y) {
GeometryFactory gf = new GeometryFactory();
Point geom = gf.createPoint(new Coordinate(x, y));
for (Geometry p : maskGeometries) {
if (p.contains(geom)) {
return true;
}
}
return false;
}
示例6: rasterize
import com.vividsolutions.jts.geom.GeometryFactory; //導入依賴的package包/類
/**
* rasterize the mask clipped with the Rectangle scaled back to full size with an offset onto a BufferedImage
*/
public BufferedImage rasterize(Rectangle rect, int offsetX, int offsetY, double scalingFactor) {
// create the buffered image of the size of the Rectangle
BufferedImage image = new BufferedImage(rect.width, rect.height, BufferedImage.TYPE_BYTE_BINARY);
GeometryFactory gf = new GeometryFactory();
// define the clipping region in full scale
Coordinate[] coords = new Coordinate[]{
new Coordinate((int) (((double) rect.getMinX() / scalingFactor)), (int) (((double) rect.getMinY() / scalingFactor))),
new Coordinate((int) (((double) rect.getMaxX() / scalingFactor)), (int) (((double) rect.getMinY() / scalingFactor))),
new Coordinate((int) (((double) rect.getMaxX() / scalingFactor)), (int) (((double) rect.getMaxY() / scalingFactor))),
new Coordinate((int) (((double) rect.getMinX() / scalingFactor)), (int) (((double) rect.getMaxY() / scalingFactor))),
new Coordinate((int) (((double) rect.getMinX() / scalingFactor)), (int) (((double) rect.getMinY() / scalingFactor))),};
Polygon geom = gf.createPolygon(gf.createLinearRing(coords));
Graphics g2d = image.getGraphics();
g2d.setColor(Color.white);
for (Geometry p : maskGeometries) {
/*if(p instanceof MultiPolygon){
p=p.getBoundary();
}*/
if (p.intersects(geom)) {
int[] xPoints = new int[p.getNumPoints()];//build array for x coordinates
int[] yPoints = new int[p.getNumPoints()];//build array for y coordinates
int i = 0;
for (Coordinate c : p.getCoordinates()) {
xPoints[i] = (int) ((c.x + offsetX ) * scalingFactor);
yPoints[i] = (int) ((c.y + offsetY ) * scalingFactor);
i++;
}
g2d.fillPolygon(xPoints, yPoints, i);
}
}
g2d.dispose();
return image;
}
示例7: repair
import com.vividsolutions.jts.geom.GeometryFactory; //導入依賴的package包/類
/**
*
* @param geom
* @return
*/
public static Geometry repair (Geometry geom) {
GeometryFactory factory = geom.getFactory();
if (geom instanceof MultiPolygon) {
MultiPolygon mp = (MultiPolygon)geom;
Polygon[] polys = new Polygon[mp.getNumGeometries()];
for (int i = 0; i < mp.getNumGeometries(); i += 1) {
polys[i] = repair((Polygon)mp.getGeometryN(i));
}
return factory.createMultiPolygon(polys);
} else if (geom instanceof Polygon) {
return repair((Polygon)geom);
} else if (geom.getGeometryType().equals("GeometryCollection")) {
GeometryCollection gc = (GeometryCollection)geom;
Geometry[] geoms = new Geometry[gc.getNumGeometries()];
for (int i = 0; i < gc.getNumGeometries(); i += 1) {
geoms[i] = repair(gc.getGeometryN(i));
}
Thread.dumpStack();
return factory.createGeometryCollection(geoms);
} else {
return(geom);
}
}
示例8: mouseClicked
import com.vividsolutions.jts.geom.GeometryFactory; //導入依賴的package包/類
/**
*
* @param imagePosition
* @param context
*/
public void mouseClicked(java.awt.Point imagePosition, OpenGLContext context) {
if(isEditable()){
this.selectedGeometry = null;
GeometryFactory gf = new GeometryFactory();
com.vividsolutions.jts.geom.Point p = gf.createPoint(new Coordinate(imagePosition.x, imagePosition.y));
for (Geometry temp : glayer.getGeometries()) {
if(temp instanceof Polygon){
Coordinate[] c=DistanceOp.nearestPoints(temp, p);
com.vividsolutions.jts.geom.Point nearest=gf.createPoint(c[0]);
if (nearest.isWithinDistance(temp,5 * context.getZoom())) {
this.selectedGeometry = temp;
System.out.println(""+temp.getCoordinate().x+","+temp.getCoordinate().y);
LayerPickedData.put(temp, glayer.getAttributes(temp));
break;
}
}
}
}
}
示例9: rasterize
import com.vividsolutions.jts.geom.GeometryFactory; //導入依賴的package包/類
public BufferedImage rasterize(BufferedImage image, int offsetX, int offsetY, double scalingFactor) {
Rectangle rect = image.getRaster().getBounds();
GeometryFactory gf = new GeometryFactory();
Coordinate[] coords = new Coordinate[]{
new Coordinate((int) (((double) rect.getMinX() / scalingFactor) + offsetX), (int) (((double) rect.getMinY() / scalingFactor) + offsetY)),
new Coordinate((int) (((double) rect.getMaxX() / scalingFactor) + offsetX), (int) (((double) rect.getMinY() / scalingFactor) + offsetY)),
new Coordinate((int) (((double) rect.getMaxX() / scalingFactor) + offsetX), (int) (((double) rect.getMaxY() / scalingFactor) + offsetY)),
new Coordinate((int) (((double) rect.getMinX() / scalingFactor) + offsetX), (int) (((double) rect.getMaxY() / scalingFactor) + offsetY)),
new Coordinate((int) (((double) rect.getMinX() / scalingFactor) + offsetX), (int) (((double) rect.getMinY() / scalingFactor) + offsetY)),
};
Polygon geom = gf.createPolygon(gf.createLinearRing(coords), null);
Graphics g2d = image.getGraphics();
g2d.setColor(Color.WHITE);
for (Geometry p : glayer.getGeometries()) {
if (p.intersects(geom)) {
int[] xPoints = new int[p.getNumPoints()];
int[] yPoints = new int[p.getNumPoints()];
int i = 0;
for (Coordinate c : p.getCoordinates()) {
xPoints[i] = (int) ((c.x - offsetX) * scalingFactor);
yPoints[i++] = (int) ((c.y - offsetY) * scalingFactor);
}
g2d.fillPolygon(xPoints, yPoints, p.getNumPoints());
}
}
g2d.dispose();
return image;
}
示例10: setup
import com.vividsolutions.jts.geom.GeometryFactory; //導入依賴的package包/類
@BeforeClass
public static void setup() {
TomtomFolder tomtomFolder = mock(TomtomFolder.class);
when(tomtomFolder.getFile("___a0.shp")).thenReturn("src/test/resources/tomtom/boundaries/a0/andorra______________a0.shp");
CapitalProvider capitalProvider = mock(CapitalProvider.class);
Point point = new Point(new PackedCoordinateSequence.Double(new double[]{1.52185, 42.50760}, 2), new GeometryFactory());
Centroid capital = new Centroid(10560000718742L, "Capital Name", "123", 0, 1, 7, point);
when(capitalProvider.get(0)).thenReturn(newArrayList(capital));
NameProvider nameProvider = mock(NameProvider.class);
when(nameProvider.getAlternateNames(10200000000008L)).thenReturn(of("name", "Andorra", "name:fr", "Andorre"));
OsmLevelGenerator osmLevelGenerator = mock(OsmLevelGenerator.class);
when(osmLevelGenerator.getOsmLevel("andorra", 0)).thenReturn("2");
BoundariesA0Shapefile shapefile = new BoundariesA0Shapefile(tomtomFolder, capitalProvider, nameProvider, osmLevelGenerator);
shapefile.serialize("target/tests/");
pbfContent = read(new File("target/tests/a0.osm.pbf"));
}
示例11: setup
import com.vividsolutions.jts.geom.GeometryFactory; //導入依賴的package包/類
@BeforeClass
public static void setup() {
TomtomFolder tomtomFolder = mock(TomtomFolder.class);
when(tomtomFolder.getFile("___a2.shp")).thenReturn("src/test/resources/tomtom/boundaries/a2/belbe2___________a2.shp");
NameProvider nameProvider = mock(NameProvider.class);
when(nameProvider.getAlternateNames(10560000000838L)).thenReturn(of("name", "Leuven"));
OsmLevelGenerator osmLevelGenerator = mock(OsmLevelGenerator.class);
when(osmLevelGenerator.getOsmLevel("belbe2", 2)).thenReturn("6");
CapitalProvider capitalProvider = mock(CapitalProvider.class);
Point point = new Point(new PackedCoordinateSequence.Double(new double[]{4.703077, 50.8756041}, 2), new GeometryFactory());
Centroid capital = new Centroid(10560000718742L, "Capital Name", "123", 2, 1, 7, point);
when(capitalProvider.get(2)).thenReturn(newArrayList(capital));
BoundariesA2Shapefile shapefile = new BoundariesA2Shapefile(tomtomFolder, capitalProvider, nameProvider, osmLevelGenerator);
shapefile.serialize("target/tests/");
pbfContent = read(new File("target/tests/a2.osm.pbf"));
}
示例12: setup
import com.vividsolutions.jts.geom.GeometryFactory; //導入依賴的package包/類
@BeforeClass
public static void setup() {
TomtomFolder tomtomFolder = mock(TomtomFolder.class);
when(tomtomFolder.getFile("___a1.shp")).thenReturn("src/test/resources/tomtom/boundaries/a1/belgium______________a1.shp");
NameProvider nameProvider = mock(NameProvider.class);
when(nameProvider.getAlternateNames(10560000000843L)).thenReturn(of("name", "Brussel", "name:fr", "Bruxelles"));
OsmLevelGenerator osmLevelGenerator = mock(OsmLevelGenerator.class);
when(osmLevelGenerator.getOsmLevel("belgium", 1)).thenReturn("4");
CapitalProvider capitalProvider = mock(CapitalProvider.class);
Point point = new Point(new PackedCoordinateSequence.Double(new double[]{4.868077, 50.4536041}, 2), new GeometryFactory());
Centroid capital = new Centroid(10560000718742L, "Capital Name", "123", 1, 1, 7, point);
when(capitalProvider.get(1)).thenReturn(newArrayList(capital));
BoundariesA1Shapefile shapefile = new BoundariesA1Shapefile(tomtomFolder, capitalProvider, nameProvider, osmLevelGenerator);
shapefile.serialize("target/tests/");
pbfContent = read(new File("target/tests/a1.osm.pbf"));
}
示例13: validateMinSegmentLength
import com.vividsolutions.jts.geom.GeometryFactory; //導入依賴的package包/類
private boolean validateMinSegmentLength(final Geometry geom, final Coordinate... coordinates) {
boolean isValid = true;
if (coordinates.length >= 2) {
for (int i = 1; i < coordinates.length; i++) {
if (!validateMinSegmentLength(coordinates[i - 1],
coordinates[i])) {
GeometryFactory geomFactory = new GeometryFactory();
errorCoordinates.add(geomFactory
.createPoint(coordinates[i]).toText());
isValid = false;
}
}
}
return isValid;
}
示例14: readGeometry
import com.vividsolutions.jts.geom.GeometryFactory; //導入依賴的package包/類
private static Geometry readGeometry(List<Integer> geomCmds,
VectorTile.Tile.GeomType geomType,
GeometryFactory geomFactory,
Vec2d cursor,
RingClassifier ringClassifier) {
Geometry result = null;
switch (geomType) {
case POINT:
result = readPoints(geomFactory, geomCmds, cursor);
break;
case LINESTRING:
result = readLines(geomFactory, geomCmds, cursor);
break;
case POLYGON:
result = readPolys(geomFactory, geomCmds, cursor, ringClassifier);
break;
default:
LoggerFactory.getLogger(MvtReader.class)
.error("readGeometry(): Unhandled geometry type [{}]", geomType);
}
return result;
}
示例15: smooth
import com.vividsolutions.jts.geom.GeometryFactory; //導入依賴的package包/類
private static Geometry smooth(final Geometry geom, final double fit,
final GeometryFactory factory, GeometrySmoother smoother) {
switch (geom.getGeometryType().toUpperCase()) {
case "POINT":
case "MULTIPOINT":
// For points, just return the input geometry
return geom;
case "LINESTRING":
// This handles open and closed lines (LinearRings)
return smoothLineString(factory, smoother, geom, fit);
case "MULTILINESTRING":
return smoothMultiLineString(factory, smoother, geom, fit);
case "POLYGON":
return smoother.smooth((Polygon) geom, fit);
case "MULTIPOLYGON":
return smoothMultiPolygon(factory, smoother, geom, fit);
case "GEOMETRYCOLLECTION":
return smoothGeometryCollection(factory, smoother, geom, fit);
default:
throw new UnsupportedOperationException("No smoothing method available for "
+ geom.getGeometryType());
}
}