本文整理匯總了Java中com.vividsolutions.jts.geom.Geometry.getCoordinates方法的典型用法代碼示例。如果您正苦於以下問題:Java Geometry.getCoordinates方法的具體用法?Java Geometry.getCoordinates怎麽用?Java Geometry.getCoordinates使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類com.vividsolutions.jts.geom.Geometry
的用法示例。
在下文中一共展示了Geometry.getCoordinates方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: getShape
import com.vividsolutions.jts.geom.Geometry; //導入方法依賴的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;
}
示例2: rasterize
import com.vividsolutions.jts.geom.Geometry; //導入方法依賴的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;
}
示例3: createImageProjected
import com.vividsolutions.jts.geom.Geometry; //導入方法依賴的package包/類
/**
* Modify the GeometricLayer so the layer coordinate system matches the image coordinate system ("pixel" projection).
*/
public static GeometryImage createImageProjected(GeometryImage layer, AffineTransform geoTransform) {
for(Geometry geom:layer.geoms){
for(Coordinate pos:geom.getCoordinates()){
Point2D.Double temp=new Point2D.Double();
try {
geoTransform.inverseTransform(new Point2D.Double(pos.x, pos.y),temp);
} catch (NoninvertibleTransformException e) {
e.printStackTrace();
}
pos.x=temp.x;
pos.y=temp.y;
}
}
return layer;
}
示例4: rasterize
import com.vividsolutions.jts.geom.Geometry; //導入方法依賴的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;
}
示例5: subGeometry
import com.vividsolutions.jts.geom.Geometry; //導入方法依賴的package包/類
/**
*
* Note: coordinate of endindex will be included
*
* @param geometry
* @param startIndex
* @param endIndex The index of the last point which shall be included in the resulting linestring !!!
* @return
*/
public static Geometry subGeometry(Geometry geometry, int startIndex,
int endIndex) {
Geometry geom = null;
Coordinate[] coords = geometry.getCoordinates();
int length = endIndex + 1 - startIndex;
if (length == 1) {
// point
Coordinate coord = coords[startIndex];
geom = gm.createPoint(coord);
geom.setSRID(geometry.getSRID());
} else if (length > 1) {
// linestring
Coordinate[] newCoords = new Coordinate[length];
System.arraycopy(coords, startIndex, newCoords, 0, length);
geom = gm.createLineString(newCoords);
geom.setSRID(geometry.getSRID());
}
return geom;
}
示例6: testCorrect3857Transform
import com.vividsolutions.jts.geom.Geometry; //導入方法依賴的package包/類
/**
* tests a coordinate transformation from epsg:4236 --> epsg:3857
*/
@Test
public void testCorrect3857Transform() {
algo.setTargetEPSG("EPSG:3857");
try {
algo.runAlgorithm();
FeatureCollection fc = algo.getResult();
FeatureIterator<?> featureIterator = fc.features();
SimpleFeature feature = (SimpleFeature) featureIterator.next();
Geometry geometry = (Geometry) feature.getDefaultGeometry();
Coordinate[] coords = geometry.getCoordinates();
assertEquals(5781631.60732, coords[0].x, 0.001);
assertEquals(1002058.9016, coords[0].y, 0.001);
assertEquals(5364555.78035, coords[1].x, 0.001);
assertEquals(908752.762799, coords[1].y, 0.001);
assertEquals(5810127.070382, coords[2].x, 0.001);
assertEquals(883747.339307, coords[2].y, 0.001);
assertEquals(5770326.33379, coords[3].x, 0.001);
assertEquals(861269.968343, coords[3].y, 0.001);
assertEquals(5581093.09574, coords[4].x, 0.001);
assertEquals(772727.762141, coords[4].y, 0.001);
} catch (Exception e) {
fail("Exception thrown: " + e.getMessage());
}
}
示例7: renderPolygons
import com.vividsolutions.jts.geom.Geometry; //導入方法依賴的package包/類
public static void renderPolygons(OpenGLContext context,float zoomWidth,float zoomHeight,List<Geometry>geometries,float size,Color color){
GL2 gl = context.getGL().getGL2();
float[] c = color.brighter().getColorComponents(null);
gl.glColor3f(c[0], c[1], c[2]);
gl.glPointSize(size);
gl.glBegin(GL.GL_POINTS);
for (Geometry temp : geometries) {
for (Coordinate point : temp.getCoordinates()) {
gl.glVertex2d((point.x - context.getX()) / zoomWidth, 1 - (point.y - context.getY()) / zoomHeight);
}
}
gl.glEnd();
gl.glFlush();
}
示例8: getShape
import com.vividsolutions.jts.geom.Geometry; //導入方法依賴的package包/類
public Area getShape(int width, int height) {
Area maskArea = new Area();
Rectangle rect = new Rectangle(0, 0, width,height);//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;
}
示例9: transformGeometryPixelFromGeo
import com.vividsolutions.jts.geom.Geometry; //導入方法依賴的package包/類
@Override
public Geometry transformGeometryPixelFromGeo(Geometry geom)throws GeoTransformException {
try{
for(Coordinate pos:geom.getCoordinates()){
double[] temp=getPixelFromGeo(pos.x, pos.y);
pos.x=temp[0];
pos.y=temp[1];
}
return geom;
}catch(Exception ge){
throw new GeoTransformException(ge.getMessage());
}
}
示例10: transformGeometryGeoFromPixel
import com.vividsolutions.jts.geom.Geometry; //導入方法依賴的package包/類
@Override
public Geometry transformGeometryGeoFromPixel(Geometry geom)throws GeoTransformException {
Geometry geomNew=(Geometry) geom.clone();
try{
for(Coordinate pos:geomNew.getCoordinates()){
double[] temp=getGeoFromPixel(pos.x, pos.y);
pos.x=temp[0];
pos.y=temp[1];
}
return geomNew;
}catch(Exception ge){
throw new GeoTransformException(ge.getMessage());
}
}
示例11: transformGeometryPixelFromGeo
import com.vividsolutions.jts.geom.Geometry; //導入方法依賴的package包/類
/**
*
*/
public Geometry transformGeometryPixelFromGeo(Geometry geom)throws GeoTransformException {
try{
Coordinate[] coords=geom.getCoordinates();
List<double[]> coordsConv=pGeo.parallelPixelFromGeo(coords);
for(int i=0;i<coords.length;i++){
coords[i].x=coordsConv.get(i)[0];
coords[i].y=coordsConv.get(i)[1];
}
return geom;
}catch(InterruptedException|ExecutionException ge){
throw new GeoTransformException(ge.getMessage());
}
}
示例12: transformGeometryGeoFromPixel
import com.vividsolutions.jts.geom.Geometry; //導入方法依賴的package包/類
@Override
public Geometry transformGeometryGeoFromPixel(final Geometry geom)
throws GeoTransformException {
try{
Coordinate[] coords=geom.getCoordinates();
List<double[]> coordsConv=pGeo.parallelGeoFromPixel(coords);
for(int i=0;i<coords.length;i++){
coords[i].x=coordsConv.get(i)[0];
coords[i].y=coordsConv.get(i)[1];
}
return geom;
}catch(InterruptedException|ExecutionException ge){
throw new GeoTransformException(ge.getMessage());
}
}
示例13: testCorrect4817Transform
import com.vividsolutions.jts.geom.Geometry; //導入方法依賴的package包/類
/**
* tests a coordinate transformation from epsg:4236 --> epsg:4817
*/
@Test
public void testCorrect4817Transform() {
algo.setTargetEPSG("EPSG:4817");
try {
algo.runAlgorithm();
FeatureCollection fc = algo.getResult();
FeatureIterator<?> featureIterator = fc.features();
SimpleFeature feature = (SimpleFeature) featureIterator.next();
Geometry geometry = (Geometry) feature.getDefaultGeometry();
Coordinate[] coords = geometry.getCoordinates();
assertEquals(41.2178843506, coords[0].x, 0.001);
assertEquals(8.95903973526, coords[0].y, 0.001);
assertEquals(37.4710724824, coords[1].x, 0.001);
assertEquals(8.13026146044, coords[1].y, 0.001);
assertEquals(41.473842952, coords[2].x, 0.001);
assertEquals(7.90771407361, coords[2].y, 0.001);
assertEquals(41.1162889713, coords[3].x, 0.001);
assertEquals(7.70767521468, coords[3].y, 0.001);
assertEquals(39.4162959551, coords[4].x, 0.001);
assertEquals(6.91879868251, coords[4].y, 0.001);
FeatureCollection result = algo.getResult();
} catch (Exception e) {
fail("Exception thrown: " + e.getMessage());
}
}
示例14: getQuery
import com.vividsolutions.jts.geom.Geometry; //導入方法依賴的package包/類
private Query getQuery(Function inner, Context context) {
RefLiteralPair innerPair = new RefLiteralPair(inner);
if (!innerPair.isValid()) {
return null;
}
if (innerPair.reference().valueType().equals(DataTypes.GEO_SHAPE)) {
// we have within('POINT(0 0)', shape_column)
return genericFunctionFilter(inner, context);
}
GeoPointFieldMapper.GeoPointFieldType geoPointFieldType = getGeoPointFieldType(
innerPair.reference().ident().columnIdent().fqn(),
context.mapperService);
Map<String, Object> geoJSON = (Map<String, Object>) innerPair.input().value();
Shape shape = GeoJSONUtils.map2Shape(geoJSON);
Geometry geometry = JtsSpatialContext.GEO.getGeometryFrom(shape);
IndexGeoPointFieldData fieldData = context.fieldDataService.getForField(geoPointFieldType);
if (geometry.isRectangle()) {
Rectangle boundingBox = shape.getBoundingBox();
return new InMemoryGeoBoundingBoxQuery(
new GeoPoint(boundingBox.getMaxY(), boundingBox.getMinX()),
new GeoPoint(boundingBox.getMinY(), boundingBox.getMaxX()),
fieldData
);
} else {
Coordinate[] coordinates = geometry.getCoordinates();
GeoPoint[] points = new GeoPoint[coordinates.length];
for (int i = 0; i < coordinates.length; i++) {
Coordinate coordinate = coordinates[i];
points[i] = new GeoPoint(coordinate.y, coordinate.x);
}
return new GeoPolygonQuery(fieldData, points);
}
}
示例15: render
import com.vividsolutions.jts.geom.Geometry; //導入方法依賴的package包/類
@Override
public void render(Object glC) {
OpenGLContext context=(OpenGLContext)glC;
super.render(context);
//OpenGLContext context=SumoPlatform.getApplication().getGeoContext();
if (!context.isDirty() || glayer == null||SumoPlatform.isBatchMode()) {
return;
}
int x = context.getX(), y = context.getY();
float zoom = context.getZoom(), width = context.getWidth() * zoom, height = context.getHeight() * zoom;
for(Additionalgeometries geometry : additionalGeometriesMap.values()){
// check geometries need to be displayed
if(geometry.isStatus()){
if (geometry.getType().equalsIgnoreCase(GeometryImage.POINT)) {
GL2ShapesRender.renderPolygons(context,width,height,geometry.getGeometries(),geometry.getLinewidth(),geometry.getColor());
} else if (geometry.getType().equalsIgnoreCase(GeometryImage.POLYGON)) {
for (Geometry tmp : geometry.getGeometries()) {
List<Geometry>gs=new ArrayList<>();
if(tmp instanceof MultiPolygon){
MultiPolygon mp=(MultiPolygon)tmp;
for (int ig=0;ig<mp.getNumGeometries();ig++) {
gs.add(mp.getGeometryN(ig));
}
}else{
gs.add(tmp);
}
for (Geometry g : gs) {
Polygon polygon=(Polygon)g;
if (polygon.getCoordinates().length < 1) {
continue;
}
GL2ShapesRender.drawPoly(context,polygon.getCoordinates(),width,height,x,y,geometry.getLinewidth(),color);
/*int interior=polygon.getNumInteriorRing();
if(interior>0){
//draw external polygon
LineString line=polygon.getExteriorRing();
GL2ShapesRender.drawPoly(context,line.getCoordinates(),width,height,x,y,geometry.getLinewidth(),color);
//draw holes
for(int i=0;i<interior;i++){
LineString line2=polygon.getInteriorRingN(i);
GL2ShapesRender.drawPoly(context,line2.getCoordinates(),width,height,x,y,geometry.getLinewidth(),color);
}
}else{
GL2ShapesRender.drawPoly(context,polygon.getCoordinates(),width,height,x,y,geometry.getLinewidth(),color);
}*/
}
}
} else if (geometry.getType().equalsIgnoreCase(GeometryImage.LINESTRING)) {
for (Geometry temp : geometry.getGeometries()) {
if (temp.getCoordinates().length < 1) {
continue;
}
GL2ShapesRender.renderPolygon(context,width,height,temp.getCoordinates(),geometry.getLinewidth(),color);
}
}
}
}
}