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


Java PreparedGeometry.intersects方法代码示例

本文整理汇总了Java中com.vividsolutions.jts.geom.prep.PreparedGeometry.intersects方法的典型用法代码示例。如果您正苦于以下问题:Java PreparedGeometry.intersects方法的具体用法?Java PreparedGeometry.intersects怎么用?Java PreparedGeometry.intersects使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在com.vividsolutions.jts.geom.prep.PreparedGeometry的用法示例。


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

示例1: main

import com.vividsolutions.jts.geom.prep.PreparedGeometry; //导入方法依赖的package包/类
public static void main(String[] args)
        throws Exception {
    Geometry circle = createCircle();
    PreparedGeometry prepCircle = PreparedGeometryFactory.prepare(circle);

    int count = 0;
    int inCount = 0;
    for (int i = 0; i < MAX_ITER; i++) {
        count++;
        Point randPt = createRandomPoint();
        if (prepCircle.intersects(randPt)) {
            inCount++;
        }

        //System.out.println("Approximation to PI: " + (4.0 * inCount / (double) count));
    }
    double approxPi = 4.0 * inCount / (double) count;
    double approxDiffPct = 1.0 - approxPi / Math.PI;

    System.out.println("Approximation to PI: " + approxPi
            + "  ( % difference from actual = " + 100 * approxDiffPct + " )"
    );

}
 
开发者ID:Semantive,项目名称:jts,代码行数:25,代码来源:PreparedGeometryExample.java

示例2: intersects

import com.vividsolutions.jts.geom.prep.PreparedGeometry; //导入方法依赖的package包/类
/**
 * Finds all {@link PreparedGeometry}s which intersect a given {@link Geometry}
 *
 * @param g the geometry to query by
 * @return a list of intersecting PreparedGeometrys
 */
public List intersects(Geometry g) {
    List result = new ArrayList();
    List candidates = query(g);
    for (Iterator it = candidates.iterator(); it.hasNext(); ) {
        PreparedGeometry prepGeom = (PreparedGeometry) it.next();
        if (prepGeom.intersects(g)) {
            result.add(prepGeom);
        }
    }
    return result;
}
 
开发者ID:Semantive,项目名称:jts,代码行数:18,代码来源:SearchUsingPreparedGeometryIndex.java

示例3: process

import com.vividsolutions.jts.geom.prep.PreparedGeometry; //导入方法依赖的package包/类
@Execute
public void process() throws Exception {
    checkNull(inRaster);

    ISurfaceInterpolator interpolator;
    if (pMode.equals(IDW)) {
        interpolator = new IDWInterpolator(pBuffer);
    } else {
        interpolator = new TPSInterpolator(pBuffer);
    }

    RegionMap regionMap = CoverageUtilities.getRegionParamsFromGridCoverage(inRaster);
    int rows = regionMap.getRows();
    int cols = regionMap.getCols();

    WritableRaster outWR = CoverageUtilities.renderedImage2WritableRaster(inRaster.getRenderedImage(), false);
    WritableRandomIter outIter = CoverageUtilities.getWritableRandomIterator(outWR);

    GridGeometry2D gridGeometry = inRaster.getGridGeometry();

    PreparedGeometry preparedRoi = null;
    if (inROI != null) {
        List<Geometry> roiList = FeatureUtilities.featureCollectionToGeometriesList(inROI, false, null);
        GeometryCollection gc = new GeometryCollection(roiList.toArray(GeometryUtilities.TYPE_GEOMETRY), gf);
        preparedRoi = PreparedGeometryFactory.prepare(gc);
    }
    pm.beginTask("Filling holes...", cols - 2);
    for( int c = 1; c < cols - 1; c++ ) {
        for( int r = 1; r < rows - 1; r++ ) {
            if (pm.isCanceled()) {
                return;
            }

            double value = outIter.getSampleDouble(c, r, 0);
            if (isNovalue(value)) {
                DirectPosition worldPosition = gridGeometry.gridToWorld(new GridCoordinates2D(c, r));
                double[] coordinate = worldPosition.getCoordinate();
                Coordinate pointCoordinate = new Coordinate(coordinate[0], coordinate[1]);
                Point point = gf.createPoint(pointCoordinate);
                if (preparedRoi == null || preparedRoi.intersects(point)) {

                    // TODO this could be done considering more points and more far away points.
                    // For now, this works.
                    List<Coordinate> surroundingValids = getValidSurroundingPoints(outIter, gridGeometry, c, r);
                    if (surroundingValids.size() > 3) {
                        double newValue = interpolator.getValue(surroundingValids.toArray(new Coordinate[0]),
                                pointCoordinate);
                        outIter.setSample(c, r, 0, newValue);
                    }
                }
            }
        }
        pm.worked(1);
    }
    pm.done();

    outIter.done();

    outRaster = CoverageUtilities.buildCoverage("nulled", outWR, regionMap, inRaster.getCoordinateReferenceSystem());
}
 
开发者ID:TheHortonMachine,项目名称:hortonmachine,代码行数:61,代码来源:OmsHoleFiller.java

示例4: process

import com.vividsolutions.jts.geom.prep.PreparedGeometry; //导入方法依赖的package包/类
@SuppressWarnings("unchecked")
@Execute
public void process() throws Exception {
    checkNull(inVector, pMaxOverlap, inRaster);

    RandomIter rasterIter = CoverageUtilities.getRandomIterator(inRaster);
    GridGeometry2D gridGeometry = inRaster.getGridGeometry();
    double[] tm_utm_tac = new double[3];

    STRtree circlesTree = FeatureUtilities.featureCollectionToSTRtree(inVector);
    List<SimpleFeature> circlesList = FeatureUtilities.featureCollectionToList(inVector);

    DefaultFeatureCollection outFC = new DefaultFeatureCollection();

    for( SimpleFeature circleFeature : circlesList ) {
        Geometry geometry = (Geometry) circleFeature.getDefaultGeometry();
        Polygon circle = (Polygon) geometry.getGeometryN(0);
        PreparedGeometry preparedCircle = PreparedGeometryFactory.prepare(circle);

        List<SimpleFeature> circlesAround = circlesTree.query(circle.getEnvelopeInternal());
        List<Geometry> intersectedCircles = new ArrayList<Geometry>();
        for( SimpleFeature circleAround : circlesAround ) {
            if (circleAround.equals(circleFeature)) {
                continue;
            }
            Geometry circleAroundGeometry = (Geometry) circleAround.getDefaultGeometry();
            if (preparedCircle.intersects(circleAroundGeometry)) {
                intersectedCircles.add(circleAroundGeometry);
            }
        }

        Point centroid = circle.getCentroid();
        int intersectionsCount = intersectedCircles.size();
        if (intersectionsCount != 0) {
            // check how many circles overlapped
            if (intersectionsCount > pMaxOverlapCount) {
                continue;
            }
            // check if the circles overlap too much, i.e. cover their baricenter
            boolean intersected = false;
            for( Geometry intersectedCircle : intersectedCircles ) {
                if (intersectedCircle.intersects(centroid)) {
                    intersected = true;
                    break;
                }
            }
            if (intersected) {
                continue;
            }
        }
        // check if the center has a raster value, i.e. is not empty
        double value = CoverageUtilities.getValue(inRaster, centroid.getCoordinate());
        if (!HMConstants.isNovalue(value)) {
            continue;
        }

        // check if the inner part of the circle is indeed rather empty

        // min, max, mean, var, sdev, activeCellCount, passiveCellCount
        double[] stats = OmsZonalStats.polygonStats(circle, gridGeometry, rasterIter, false, tm_utm_tac, 0, pm);
        // if we have many more active cells than passive cells, that is not a circle
        double activeCells = stats[5];
        double novalues = stats[6];
        if (activeCells * 1.5 > novalues) {
            continue;
        }

        // take it as valid circle
        outFC.add(circleFeature);
    }
    outCircles = outFC;

    rasterIter.done();
}
 
开发者ID:TheHortonMachine,项目名称:hortonmachine,代码行数:75,代码来源:OmsHoughCirclesRasterCleaner.java

示例5: process

import com.vividsolutions.jts.geom.prep.PreparedGeometry; //导入方法依赖的package包/类
@Execute
public void process() throws Exception {
    checkNull(inMap1, inMap2);

    outMap = new DefaultFeatureCollection();

    if (!doKeepFirstAttributes) {
        SimpleFeatureCollection inMapTmp = inMap1;
        inMap1 = inMap2;
        inMap2 = inMapTmp;
    }

    List<Geometry> geometries = FeatureUtilities.featureCollectionToGeometriesList(inMap2, false, null);
    GeometryCollection geometryCollection = new GeometryCollection(geometries.toArray(new Geometry[geometries.size()]), gf);
    Geometry intersectionGeometry = geometryCollection.buffer(0);
    PreparedGeometry preparedIntersectionGeometry = PreparedGeometryFactory.prepare(intersectionGeometry);

    List<SimpleFeature> mainFeatures = FeatureUtilities.featureCollectionToList(inMap1);
    if (mainFeatures.size() == 0) {
        throw new ModelsIllegalargumentException("No features found in the layer.", this);
    }

    EGeometryType geometryType = EGeometryType.forGeometry((Geometry) mainFeatures.get(0).getDefaultGeometry());
    Class< ? > multiClazz = geometryType.getMultiClazz();
    EGeometryType newGeometryType = EGeometryType.forClass(multiClazz);
    FeatureGeometrySubstitutor sub = new FeatureGeometrySubstitutor(inMap1.getSchema(), multiClazz);

    pm.beginTask("Performing intersection...", mainFeatures.size());
    for( SimpleFeature feature : mainFeatures ) {
        Geometry geometry = (Geometry) feature.getDefaultGeometry();
        if (preparedIntersectionGeometry.intersects(geometry)) {
            Geometry intersection = geometry.intersection(intersectionGeometry);

            EGeometryType intersectionGeometryType = EGeometryType.forGeometry(intersection);
            if (intersectionGeometryType.isCompatibleWith(newGeometryType)) {
                SimpleFeature newFeature = sub.substituteGeometry(feature, intersection);
                ((DefaultFeatureCollection) outMap).add(newFeature);
            } else {
                pm.errorMessage("Could not add intersection result geometry to layer due to incompatibility: " + intersection);
            }
        }
        pm.worked(1);
    }
    pm.done();

}
 
开发者ID:TheHortonMachine,项目名称:hortonmachine,代码行数:47,代码来源:OmsVectorIntersector.java

示例6: getEnvelopesInGeometry

import com.vividsolutions.jts.geom.prep.PreparedGeometry; //导入方法依赖的package包/类
/**
 * Retrieve all the trees envelopes that intersect the geometry.
 *
 * @param checkGeom the {@link com.vividsolutions.jts.geom.Geometry} to use to check.
 * @param doOnlyEnvelope check for the geom envelope instead of a intersection with it.
 * @param minMaxZ an array to be filled with the min and max z to be used as style.
 * @return the list of envelopes contained in the supplied geometry.
 * @throws Exception
 */
@Override
public synchronized List<Geometry> getEnvelopesInGeometry( Geometry checkGeom, boolean doOnlyEnvelope, double[] minMaxZ )
        throws Exception {
    checkOpen();
    ArrayList<Geometry> envelopeListForTile = new ArrayList<Geometry>();

    Envelope env = checkGeom.getEnvelopeInternal();
    PreparedGeometry preparedGeometry = null;
    if (!doOnlyEnvelope) {
        preparedGeometry = PreparedGeometryFactory.prepare(checkGeom);
    }
    double min = Double.POSITIVE_INFINITY;
    double max = Double.NEGATIVE_INFINITY;
    List< ? > filesList = mainLasFolderIndex.query(env);
    for( Object fileName : filesList ) {
        if (fileName instanceof String) {
            String name = (String) fileName;
            File lasFile = new File(lasFolder, name);
            File lasIndexFile = FileUtilities.substituteExtention(lasFile, "lasfix");

            String absolutePath = lasIndexFile.getAbsolutePath();
            STRtreeJGT lasIndex = fileName2IndexMap.get(absolutePath);
            if (lasIndex == null) {
                lasIndex = OmsLasIndexReader.readIndex(absolutePath);
                fileName2IndexMap.put(absolutePath, lasIndex);
            }
            List< ? > queryBoundables = lasIndex.queryBoundables(env);
            for( Object object : queryBoundables ) {
                if (object instanceof ItemBoundable) {
                    ItemBoundable itemBoundable = (ItemBoundable) object;
                    double[] item = (double[]) itemBoundable.getItem();
                    if (item.length > 0) {
                        Envelope bounds = (Envelope) itemBoundable.getBounds();
                        Polygon envelopePolygon = LasIndexer.envelopeToPolygon(bounds);
                        envelopePolygon.setUserData(new double[]{item[2], item[3]});
                        if (minMaxZ != null) {
                            min = Math.min(min, item[2]);
                            max = Math.max(max, item[2]);
                        }
                        if (doOnlyEnvelope) {
                            envelopeListForTile.add(envelopePolygon);
                        } else {
                            if (preparedGeometry.intersects(envelopePolygon)) {
                                envelopeListForTile.add(envelopePolygon);
                            }
                        }
                    }
                }
            }
        }
    }
    if (minMaxZ != null) {
        minMaxZ[0] = min;
        minMaxZ[1] = max;
    }
    return envelopeListForTile;
}
 
开发者ID:TheHortonMachine,项目名称:hortonmachine,代码行数:67,代码来源:LasFolderIndexDataManager.java

示例7: compare

import com.vividsolutions.jts.geom.prep.PreparedGeometry; //导入方法依赖的package包/类
@Override
public boolean compare(
		final Geometry dataGeometry,
		final PreparedGeometry constraintGeometry ) {
	return constraintGeometry.intersects(dataGeometry);
}
 
开发者ID:locationtech,项目名称:geowave,代码行数:7,代码来源:SpatialQueryFilter.java


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