當前位置: 首頁>>代碼示例>>Java>>正文


Java Geometry類代碼示例

本文整理匯總了Java中com.vividsolutions.jts.geom.Geometry的典型用法代碼示例。如果您正苦於以下問題:Java Geometry類的具體用法?Java Geometry怎麽用?Java Geometry使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


Geometry類屬於com.vividsolutions.jts.geom包,在下文中一共展示了Geometry類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: flatten

import com.vividsolutions.jts.geom.Geometry; //導入依賴的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: getSharedAreaRatio

import com.vividsolutions.jts.geom.Geometry; //導入依賴的package包/類
/** */
public static double getSharedAreaRatio (Geometry geom1, Geometry geom2) {
    try {
        return geom1.intersection(geom2).getArea() / geom1.getArea();
    } catch (TopologyException e) {
        // HACK: there appears to be a bug in JTS, but I can't
        // reproduce it consistently. Why should computing the
        // intersection with a MultiPolygon fail when computing
        // the intersection with each of its constituent Polygons
        // succeeds? I have no idea, but it does happen. This
        // seems to fix the problem, though.
        double result = 0.0;
        if (geom2 instanceof GeometryCollection) {
            GeometryCollection gc = (GeometryCollection)geom2;
            for (int j = 0; j < gc.getNumGeometries(); j += 1) {
                result += geom1.intersection(gc.getGeometryN(j)).getArea();
            }
            return result / geom1.getArea();
        } else {
            throw e;
        }
    }
}
 
開發者ID:ec-europa,項目名稱:sumo,代碼行數:24,代碼來源:JTSUtil.java

示例3: testNegExtPolyRings

import com.vividsolutions.jts.geom.Geometry; //導入依賴的package包/類
@Test
public void testNegExtPolyRings() {
  try {
    // Single MultiPolygon with two triangles that have negative area from shoelace formula
    // Support for 'V1' MVTs.
    final JtsMvt mvt = loadMvt(
        "src/test/resources/mapbox/vector_tile_js/multi_poly_neg_exters.mvt",
        MvtReader.RING_CLASSIFIER_V1);
    final List<Geometry> geoms = getAllGeometries(mvt);

    assertEquals(1, geoms.size());
    assertTrue(geoms.get(0) instanceof MultiPolygon);
  } catch (IOException exception) {
    fail(exception.getMessage());
  }
}
 
開發者ID:OrdnanceSurvey,項目名稱:vt-support,代碼行數:17,代碼來源:MvtReaderTest.java

示例4: GeometryImage

import com.vividsolutions.jts.geom.Geometry; //導入依賴的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);
       }
   }
 
開發者ID:ec-europa,項目名稱:sumo,代碼行數:22,代碼來源:GeometryImage.java

示例5: checkJTSFootprint

import com.vividsolutions.jts.geom.Geometry; //導入依賴的package包/類
/**
 * Check JTS Footprint validity
 */
public static boolean checkJTSFootprint (String footprint)
{
   try
   {
      WKTReader wkt = new WKTReader();
      Geometry geom = wkt.read(footprint);
      IsValidOp vaildOp = new IsValidOp(geom);
      TopologyValidationError err = vaildOp.getValidationError();
      if (err != null)
      {
         throw new IllegalParameterException(err.getMessage());
      }
      return true;
   }
   catch (Exception e)
   {
      LOGGER.error("JTS Footprint error : " + e.getMessage());
      return false;
   }
}
 
開發者ID:SentinelDataHub,項目名稱:dhus-core,代碼行數:24,代碼來源:ProcessingUtils.java

示例6: BlackBorderAnalysis

import com.vividsolutions.jts.geom.Geometry; //導入依賴的package包/類
public BlackBorderAnalysis(GeoImageReader gir,int hTileSize,int vTileSize,List<Geometry> land) {
	this.gir=gir;

	//if there is an image with cross-pol (HV or VH) we use it
	int nb=gir.getNBand();
	if(nb>1){
		for(int i=0;i<nb;i++){
			if(gir.getBandName(i).equalsIgnoreCase("HV")||gir.getBandName(i).equalsIgnoreCase("VH")){
				bandAnalysis=i;
				break;
			}
		}
	}

	 // the real size of tiles
       sizeX = hTileSize;    //x step
       sizeY = vTileSize;	   //y step

       horTiles=gir.getWidth()/hTileSize;
       verTiles=gir.getHeight()/vTileSize;

       iNPixExtremes=hTileSize<vTileSize?vTileSize/10:hTileSize/10;

       this.land=land;
}
 
開發者ID:ec-europa,項目名稱:sumo,代碼行數:26,代碼來源:BlackBorderAnalysis.java

示例7: checkIfTileIsOnLand

import com.vividsolutions.jts.geom.Geometry; //導入依賴的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;
}
 
開發者ID:ec-europa,項目名稱:sumo,代碼行數:31,代碼來源:BlackBorderAnalysis.java

示例8: polyStats

import com.vividsolutions.jts.geom.Geometry; //導入依賴的package包/類
private static FeatureStats polyStats(Geometry geom) {
  final FeatureStats featureStats = new FeatureStats();

  for (int i = 0; i < geom.getNumGeometries(); ++i) {
    final Polygon nextPoly = (Polygon) geom.getGeometryN(i);

    // Stats: exterior ring
    final LineString exteriorRing = nextPoly.getExteriorRing();
    featureStats.totalPts += exteriorRing.getNumPoints();
    featureStats.repeatedPts += checkRepeatedPoints2d(exteriorRing);

    // Stats: interior rings
    for (int ringIndex = 0; ringIndex < nextPoly.getNumInteriorRing(); ++ringIndex) {

      final LineString nextInteriorRing = nextPoly.getInteriorRingN(ringIndex);
      featureStats.totalPts += nextInteriorRing.getNumPoints();
      featureStats.repeatedPts += checkRepeatedPoints2d(nextInteriorRing);
    }
  }

  return featureStats;
}
 
開發者ID:OrdnanceSurvey,項目名稱:vt-support,代碼行數:23,代碼來源:JtsGeomStats.java

示例9: contains

import com.vividsolutions.jts.geom.Geometry; //導入依賴的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;
}
 
開發者ID:ec-europa,項目名稱:sumo,代碼行數:11,代碼來源:MaskGeometries.java

示例10: 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;

}
 
開發者ID:ec-europa,項目名稱:sumo,代碼行數:43,代碼來源:MaskGeometries.java

示例11: printGeoms

import com.vividsolutions.jts.geom.Geometry; //導入依賴的package包/類
/**
 * Print geometries.
 *
 * @param geoms the geometries
 * @throws IOException thrown when IO error
 */
public static void printGeoms(Collection<Geometry> geoms) throws IOException {
  System.out.println("Attribute Info");
  System.out.println("---------------");

  for (Geometry geom : geoms) {
    if (geom.getUserData() == null) {
      System.out.println("no user data");
      return;
    }

    Map<?,?> attributes = (Map) geom.getUserData();
    for (Map.Entry entry : attributes.entrySet()) {
      System.out.println(entry.getKey() + " -> " + entry.getValue());
    }
    System.out.println("");
  }
}
 
開發者ID:OrdnanceSurvey,項目名稱:vt-support,代碼行數:24,代碼來源:PrintUtil.java

示例12: computePath

import com.vividsolutions.jts.geom.Geometry; //導入依賴的package包/類
private PoseSteering[] computePath(PoseSteering from, PoseSteering ... to) {
	if (USE_MP) {
		ReedsSheppCarPlanner rsp = new ReedsSheppCarPlanner();
		if (this.mapFileName == null) {
			rsp.setMapFilename(makeEmptyMapMap());
			rsp.setMapResolution(1.0);
		}
		else {
			rsp.setMapFilename(mapImgFileName);
			rsp.setMapResolution(mapRes);
		}
		rsp.setRadius(3.0);
		rsp.setTurningRadius(MAX_TURNING_RADIUS);
		rsp.setDistanceBetweenPathPoints(MIN_DISTANCE_BETWEEN_PATH_POINTS);
		rsp.setStart(from.getPose());
		Pose[] goalPoses = new Pose[to.length];
		for (int i = 0; i < goalPoses.length; i++) goalPoses[i] = to[i].getPose();
		rsp.setGoals(goalPoses);
		rsp.addObstacles(obstacles.toArray(new Geometry[obstacles.size()]));
		if (!rsp.plan()) return null;
		PoseSteering[] ret = rsp.getPath();
		return ret;
	}
	Coordinate[] controlPoints = new Coordinate[4];
	controlPoints[0] = new Coordinate(from.getX(),from.getY(),0.0);
	double d = MAX_TURNING_RADIUS;
	controlPoints[1] = new Coordinate(from.getX()+d*Math.cos(from.getTheta()), from.getY()+d*Math.sin(from.getTheta()), 0.0);
	controlPoints[2] = new Coordinate(to[to.length-1].getX()-d*Math.cos(to[to.length-1].getTheta()), to[to.length-1].getY()-d*Math.sin(to[to.length-1].getTheta()), 0.0);
	controlPoints[3] = new Coordinate(to[to.length-1].getX(),to[to.length-1].getY(),0.0);
	Spline3D spline1 = SplineFactory.createBezier(controlPoints, 0.5);
	return spline1.asPoseSteerings();
}
 
開發者ID:FedericoPecora,項目名稱:coordination_oru,代碼行數:33,代碼來源:PathEditor.java

示例13: getEnvelope

import com.vividsolutions.jts.geom.Geometry; //導入依賴的package包/類
@Override
public List<String> getEnvelope(final List<String> wkts)
		throws IllegalArgumentException {
	Geometry resultGeometry = null;

	final List<String> result = new ArrayList<String>();

	for (final String wkt : wkts) {
		Geometry geom = getGeometry(wkt);
		geom = geom.buffer(TOLERANCIA_ENVELOPE);

		if (resultGeometry == null) {
			resultGeometry = geom;
		} else {
			resultGeometry = resultGeometry.union(geom);
		}
	}

	if (resultGeometry != null) {
		result.add(resultGeometry.getEnvelope().toText());
	}

	return result;
}
 
開發者ID:geowe,項目名稱:sig-seguimiento-vehiculos,代碼行數:25,代碼來源:JTSServiceImpl.java

示例14: getFrame

import com.vividsolutions.jts.geom.Geometry; //導入依賴的package包/類
public static Geometry getFrame(GeoImageReader gir) throws GeoTransformException{
    try {
        GeoTransform gt = gir.getGeoTransform();
        double[] x0;
        double[] x1;
        double[] x2;
        double[] x3;
        x0 = gt.getGeoFromPixel(-50, -50);
        x2 = gt.getGeoFromPixel(50 + gir.getWidth(), 50 + gir.getHeight());
        x3 = gt.getGeoFromPixel(50 + gir.getWidth(), -50);
        x1 = gt.getGeoFromPixel(-50, 50 + gir.getHeight());
        return new WKTReader().read("POLYGON((" + x0[0] + " " + x0[1] + "," + x1[0] + " " + x1[1] + "," + x2[0] + " " + x2[1] + "," + x3[0] + " " + x3[1] + "," + x0[0] + " " + x0[1] + "" + "))");
    } catch (ParseException ex) {
    	logger.error(ex.getMessage(),ex);
    }
    return null;
}
 
開發者ID:ec-europa,項目名稱:sumo,代碼行數:18,代碼來源:GeometryExtractor.java

示例15: getLength

import com.vividsolutions.jts.geom.Geometry; //導入依賴的package包/類
public static double getLength(Geometry geom, Boolean inMeters) throws Exception
{
	if (!(geom instanceof LineString))
		throw new Exception("Specified geometry type is not supported.");

	LineString ls = (LineString)geom;
	if (ls.getNumPoints() == 0)
		return 0.0;

	if (inMeters)
	{
		double length = 0.0;
		DistanceCalc dc = new DistanceCalcEarth();

		Coordinate c0  = ls.getCoordinateN(0);
		for (int i = 1; i < ls.getNumPoints(); ++i)
		{
			Coordinate c1 = ls.getCoordinateN(i);
			length += dc.calcDist(c0.y, c0.x, c1.y, c1.x);
			c0 = c1;
		}

		return length;
	}
	else
		return ls.getLength();
}
 
開發者ID:GIScience,項目名稱:openrouteservice,代碼行數:28,代碼來源:GeomUtility.java


注:本文中的com.vividsolutions.jts.geom.Geometry類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。