当前位置: 首页>>代码示例>>Java>>正文


Java Polygon类代码示例

本文整理汇总了Java中com.vividsolutions.jts.geom.Polygon的典型用法代码示例。如果您正苦于以下问题:Java Polygon类的具体用法?Java Polygon怎么用?Java Polygon使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


Polygon类属于com.vividsolutions.jts.geom包,在下文中一共展示了Polygon类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: flatten

import com.vividsolutions.jts.geom.Polygon; //导入依赖的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));
    }
}
 
开发者ID:ec-europa,项目名称:sumo,代码行数:25,代码来源:JTSUtil.java

示例2: getShape

import com.vividsolutions.jts.geom.Polygon; //导入依赖的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;
}
 
开发者ID:ec-europa,项目名称:sumo,代码行数:27,代码来源:InterpolatedVectorLayer.java

示例3: createPolygon

import com.vividsolutions.jts.geom.Polygon; //导入依赖的package包/类
/**
 *
 * @param xs
 * @return
 * @throws ParseException
 */
public static Polygon createPolygon(double[]...xs) throws ParseException{
	StringBuilder builder =new StringBuilder("POLYGON((");

	for(int i=0;i<xs.length;i++){
		double x[]=xs[i];
		if(i<(xs.length-1))
			builder=builder.append(x[0]).append(" ").append(x[1]).append(",");
		else
			builder=builder.append(x[0]).append(" ").append(x[1]).append("))");
	}
	Polygon imageP = (Polygon) new WKTReader().read(builder.toString());
	/*Coordinate[]cs=new Coordinate[xs.length];
	for(int i=0;i<xs.length;i++){
		cs[i]=new Coordinate(xs[i][0],xs[i][1]);
	}
	GeometryFactory factor=new GeometryFactory();
	Polygon imageP=factor.createPolygon(cs);*/

	return imageP;
}
 
开发者ID:ec-europa,项目名称:sumo,代码行数:27,代码来源:PolygonOp.java

示例4: rasterize

import com.vividsolutions.jts.geom.Polygon; //导入依赖的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;

}
 
开发者ID:ec-europa,项目名称:sumo,代码行数:43,代码来源:MaskGeometries.java

示例5: loadShapeFile

import com.vividsolutions.jts.geom.Polygon; //导入依赖的package包/类
/**
 *
 * @param args
 */
private GeometryImage loadShapeFile(File file,String name){//String[] args) {
    GeometryImage gl=null;

    ImageLayer imgLayer=LayerManager.getIstanceManager().getCurrentImageLayer();
    if(imgLayer!=null){
    	try {
    		Polygon imageP=((SarImageReader)imgLayer.getImageReader()).getBbox(PlatformConfiguration.getConfigurationInstance().getLandMaskMargin(0));
    		long start=System.currentTimeMillis();
             gl = SimpleShapefile.createIntersectedLayer(file,imageP,((SarImageReader)imgLayer.getImageReader()).getGeoTransform());
            long end=System.currentTimeMillis();
            System.out.println("Shapefile loaded in:"+(end-start));
            // if 5 args, set a specific name
            if (name!=null&&!name.equals("")) {
                if (gl != null) {
                    gl.setName(name);
                }
            }
        } catch (Exception ex) {
            logger.error(ex.getMessage(), ex);
        }
    }
    return gl;
}
 
开发者ID:ec-europa,项目名称:sumo,代码行数:28,代码来源:AddVectorConsoleAction.java

示例6: compare

import com.vividsolutions.jts.geom.Polygon; //导入依赖的package包/类
public int compare (Polygon p1, Polygon p2) {
    if (p1.contains(p2)) {
        return(1);
    } else if (p2.contains(p1)) {
        return(-1);
    } else {
        return(0);
    }
}
 
开发者ID:ec-europa,项目名称:sumo,代码行数:10,代码来源:JTSUtil.java

示例7: repair

import com.vividsolutions.jts.geom.Polygon; //导入依赖的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);
    }
}
 
开发者ID:ec-europa,项目名称:sumo,代码行数:29,代码来源:JTSUtil.java

示例8: mouseClicked

import com.vividsolutions.jts.geom.Polygon; //导入依赖的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;
          }
     	}
     }
	}
}
 
开发者ID:ec-europa,项目名称:sumo,代码行数:25,代码来源:MaskVectorLayer.java

示例9: smooth

import com.vividsolutions.jts.geom.Polygon; //导入依赖的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());
    }
}
 
开发者ID:GIScience,项目名称:openrouteservice,代码行数:31,代码来源:JTS.java

示例10: rasterize

import com.vividsolutions.jts.geom.Polygon; //导入依赖的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;
}
 
开发者ID:ec-europa,项目名称:sumo,代码行数:29,代码来源:InterpolatedVectorLayer.java

示例11: should_split_polygon_in_16

import com.vividsolutions.jts.geom.Polygon; //导入依赖的package包/类
@Test
public void should_split_polygon_in_16() {
    Polygon polygon = polygon(
            new Coordinate(0.0, 0.0),
            new Coordinate(1.0, 0.0),
            new Coordinate(1.0, 1.0),
            new Coordinate(0.0, 1.0),
            new Coordinate(0.0, 0.0));

    List<Geometry> geoms = LargePolygonSplitter.split(polygon, 0.1);

    assertThat(geoms).extracting(Geometry::toString).hasSize(16).contains(
            "POLYGON ((0.25 0, 0 0, 0 0.25, 0.25 0.25, 0.25 0))",
            "POLYGON ((0 0.25, 0 0.5, 0.25 0.5, 0.25 0.25, 0 0.25))",
            "POLYGON ((0.25 0.5, 0.5 0.5, 0.5 0.25, 0.25 0.25, 0.25 0.5))");
}
 
开发者ID:Mappy,项目名称:fpm,代码行数:17,代码来源:LargePolygonSplitterTest.java

示例12: checkSearchRadius

import com.vividsolutions.jts.geom.Polygon; //导入依赖的package包/类
private static void checkSearchRadius(Geometry geom, double value) throws Exception
{
	if (geom instanceof Point)
	{
		if (LocationsServiceSettings.getMaximumSearchRadiusForPoints() > 0 && LocationsServiceSettings.getMaximumSearchRadiusForPoints() < value)
			throw new ParameterOutOfRangeException(LocationsErrorCodes.PARAMETER_VALUE_EXCEEDS_MAXIMUM, "radius", Double.toString(value), Double.toString(LocationsServiceSettings.getMaximumSearchRadiusForPoints()));
	}
	else if (geom instanceof LineString)
	{
		if (LocationsServiceSettings.getMaximumSearchRadiusForLinestrings() > 0 && LocationsServiceSettings.getMaximumSearchRadiusForLinestrings() < value)
			throw new ParameterOutOfRangeException(LocationsErrorCodes.PARAMETER_VALUE_EXCEEDS_MAXIMUM, "radius", Double.toString(value), Double.toString(LocationsServiceSettings.getMaximumSearchRadiusForLinestrings()));
	}
	else if (geom instanceof Polygon)
	{
		if (LocationsServiceSettings.getMaximumSearchRadiusForPolygons() > 0 && LocationsServiceSettings.getMaximumSearchRadiusForPolygons() < value)
			throw new ParameterOutOfRangeException(LocationsErrorCodes.PARAMETER_VALUE_EXCEEDS_MAXIMUM, "radius", Double.toString(value), Double.toString(LocationsServiceSettings.getMaximumSearchRadiusForPolygons()));
	}
}
 
开发者ID:GIScience,项目名称:openrouteservice,代码行数:19,代码来源:JsonLocationsRequestParser.java

示例13: main

import com.vividsolutions.jts.geom.Polygon; //导入依赖的package包/类
public static void main(String[] args) {
	ReedsSheppCarPlanner rsp = new ReedsSheppCarPlanner();
	Coordinate footprint1 = new Coordinate(-2.0,0.5);
	Coordinate footprint2 = new Coordinate(2.0,0.5);
	Coordinate footprint3 = new Coordinate(2.0,-0.5);
	Coordinate footprint4 = new Coordinate(-2.0,-0.5);
	rsp.setRadius(0.5);
	rsp.setFootprint(footprint1,footprint2,footprint3,footprint4);
	JTSDrawingPanel panel = JTSDrawingPanel.makeEmpty("debug");
	GeometryFactory gf = new GeometryFactory();
	Polygon footprint = gf.createPolygon(new Coordinate[] {footprint1,footprint2,footprint3,footprint4,footprint1});
	Polygon smoothedFootprint = gf.createPolygon(rsp.getCollisionCircleCenters());
	System.out.println("Smoothing went from " + footprint.getCoordinates().length + " to " + smoothedFootprint.getCoordinates().length + " points");
	panel.addGeometry("orig", footprint, true, true, true, "#00FF00");
	panel.addGeometry("smooth", smoothedFootprint, false, false, true, "#FF0000");
	for (int i = 0; i < smoothedFootprint.getCoordinates().length; i++) {
		double delta = 0.1;
		Coordinate p1 = new Coordinate(smoothedFootprint.getCoordinates()[i].x,smoothedFootprint.getCoordinates()[i].y);
		Coordinate p2 = new Coordinate(smoothedFootprint.getCoordinates()[i].x+delta,smoothedFootprint.getCoordinates()[i].y+delta);
		Coordinate p3 = new Coordinate(smoothedFootprint.getCoordinates()[i].x-delta,smoothedFootprint.getCoordinates()[i].y+delta);
		panel.addGeometry("_cp"+i, gf.createPolygon(new Coordinate[] {p1,p2,p3,p1}), false, false, false, "#000000");
	}
	

}
 
开发者ID:FedericoPecora,项目名称:coordination_oru,代码行数:26,代码来源:TestReedsSheppCarPlannerSmoothGeometry.java

示例14: removeCollinearVertices

import com.vividsolutions.jts.geom.Polygon; //导入依赖的package包/类
/**
 * Removes collinear vertices from the provided {@link Geometry}.
 * 
 * <p>
 * For the moment this implementation only accepts, {@link Polygon}, {@link LineString} and {@link MultiPolygon} It will throw an exception if the
 * geometry is not one of those types
 * 
 * @param g the instance of a {@link Geometry} to remove collinear vertices from.
 * @return a new instance of the provided {@link Geometry} without collinear vertices.
 */
public static Geometry removeCollinearVertices(final Geometry g) {
    if (g == null) {
        throw new NullPointerException("The provided Geometry is null");
    }
    if (g instanceof LineString) {
        return removeCollinearVertices((LineString) g);
    } else if (g instanceof Polygon) {
        return removeCollinearVertices((Polygon) g);
    } else if (g instanceof MultiPolygon) {
        MultiPolygon mp = (MultiPolygon) g;
        Polygon[] parts = new Polygon[mp.getNumGeometries()];
        for (int i = 0; i < mp.getNumGeometries(); i++) {
            Polygon part = (Polygon) mp.getGeometryN(i);
            part = removeCollinearVertices(part);
            parts[i] = part;
        }

        return g.getFactory().createMultiPolygon(parts);
    }

    throw new IllegalArgumentException(
            "This method can work on LineString, Polygon and Multipolygon: " + g.getClass());
}
 
开发者ID:GIScience,项目名称:openrouteservice,代码行数:34,代码来源:JTS.java

示例15: mergePolygons

import com.vividsolutions.jts.geom.Polygon; //导入依赖的package包/类
/**
*
* @param polygons
* @return
*/
  public static List<Geometry> mergePolygons(List<Geometry> polygons) {
  	boolean done;
  	do {
  	done = true;
  	for (int i = 0; i < polygons.size(); i++) {
  		Geometry a = polygons.get(i);
  	    for (int j = i + 1; j < polygons.size();) {
  	        final Geometry b = polygons.get(j);
  	        if (a.intersects(b)) {

  	            polygons.set(i, (Polygon) a.union(b));
  	            a = polygons.get(i);
  	            polygons.remove(j);
  	            done = false;
  	        }
  	        else {
  	            j++;
  	        }
  	    }
  	}
  	} while (!done);

  	return polygons;
  }
 
开发者ID:ec-europa,项目名称:sumo,代码行数:30,代码来源:PolygonOp.java


注:本文中的com.vividsolutions.jts.geom.Polygon类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。