本文整理汇总了Java中com.vividsolutions.jts.geom.prep.PreparedGeometryFactory类的典型用法代码示例。如果您正苦于以下问题:Java PreparedGeometryFactory类的具体用法?Java PreparedGeometryFactory怎么用?Java PreparedGeometryFactory使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
PreparedGeometryFactory类属于com.vividsolutions.jts.geom.prep包,在下文中一共展示了PreparedGeometryFactory类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: main
import com.vividsolutions.jts.geom.prep.PreparedGeometryFactory; //导入依赖的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 + " )"
);
}
示例2: insert
import com.vividsolutions.jts.geom.prep.PreparedGeometryFactory; //导入依赖的package包/类
/**
* Inserts a collection of Geometrys into the index.
*
* @param geoms a collection of Geometrys to insert
*/
public void insert(Collection geoms) {
for (Iterator i = geoms.iterator(); i.hasNext(); ) {
Geometry geom = (Geometry) i.next();
index.insert(geom.getEnvelopeInternal(), PreparedGeometryFactory.prepare(geom));
}
}
示例3: intersectingFeatures
import com.vividsolutions.jts.geom.prep.PreparedGeometryFactory; //导入依赖的package包/类
/** */
public List<VectorFeature> intersectingFeatures (Geometry geom) {
final PreparedGeometry pGeom = PreparedGeometryFactory.prepare(geom);
final List<VectorFeature> result = new ArrayList<VectorFeature>();
_spatialIndex.query(geom.getEnvelopeInternal(), new ItemVisitor() {
public void visitItem (Object item) {
VectorFeature feature = (VectorFeature)item;
if (pGeom.intersects(feature.getGeometry())) {
result.add(feature);
}
}
});
return result;
}
示例4: load
import com.vividsolutions.jts.geom.prep.PreparedGeometryFactory; //导入依赖的package包/类
private Shapefile load() {
if (state.compareAndSet(NOT_LOADED, LOADED)) {
try {
final List<PreparedGeometry> geometries = new ArrayList<>();
for (String typeName : datastore.getTypeNames()) {
SimpleFeatureSource source = datastore.getFeatureSource(typeName);
crs = source.getBounds().getCoordinateReferenceSystem();
final SimpleFeatureCollection features = source.getFeatures();
SimpleFeatureIterator it = features.features();
while (it.hasNext()) {
SimpleFeature feature = it.next();
Geometry g = (Geometry) feature.getDefaultGeometry();
if (bufferDistance > 0)
g = g.buffer(bufferDistance);
geometries.add(PreparedGeometryFactory.prepare(g));
this.features.add(feature);
}
it.close();
}
this.geometries = geometries;
} catch (IOException e) {
throw new RuntimeException(e);
}
} else if (state.get() == CLOSED)
throw new RuntimeException("Shapefile is closed and can't be accessed");
return this;
}
示例5: FastLiteShape
import com.vividsolutions.jts.geom.prep.PreparedGeometryFactory; //导入依赖的package包/类
public FastLiteShape( Geometry geom ) {
super(geom, new AffineTransform(), false);
this.prepared = PreparedGeometryFactory.prepare(geom);
GeometryFactory gf = new GeometryFactory();
pointCS = new LiteCoordinateSequence(1, 2);
point = gf.createPoint(pointCS);
rectCS = new LiteCoordinateSequence(5, 2);
rect = gf.createPolygon(gf.createLinearRing(rectCS), null);
// System.out.println("Crop area: " + geom);
}
示例6: intersects
import com.vividsolutions.jts.geom.prep.PreparedGeometryFactory; //导入依赖的package包/类
/**
* Check for intersection.
*
* @param geometry the geometry to check against.
* @param usePrepared use prepared geometry.
* @return true if the geometries intersect.
*/
public boolean intersects( Geometry geometry, boolean usePrepared ) {
if (!getEnvelope().intersects(geometry.getEnvelopeInternal())) {
return false;
}
if (usePrepared) {
if (preparedGeometry == null) {
preparedGeometry = PreparedGeometryFactory.prepare(getGeometry());
}
return preparedGeometry.intersects(geometry);
} else {
return getGeometry().intersects(geometry);
}
}
示例7: covers
import com.vividsolutions.jts.geom.prep.PreparedGeometryFactory; //导入依赖的package包/类
/**
* Check for cover.
*
* @param geometry the geometry to check against.
* @param usePrepared use prepared geometry.
* @return true if the current geometries covers the supplied one.
*/
public boolean covers( Geometry geometry, boolean usePrepared ) {
if (!getEnvelope().covers(geometry.getEnvelopeInternal())) {
return false;
}
if (usePrepared) {
if (preparedGeometry == null) {
preparedGeometry = PreparedGeometryFactory.prepare(getGeometry());
}
return preparedGeometry.covers(geometry);
} else {
return getGeometry().covers(geometry);
}
}
示例8: linkBasinWithNetwork
import com.vividsolutions.jts.geom.prep.PreparedGeometryFactory; //导入依赖的package包/类
private void linkBasinWithNetwork() throws Exception {
FeatureExtender fExt = new FeatureExtender(inNetwork.getSchema(), new String[]{NetworkChannel.NETNUMNAME},
new Class[]{Integer.class});
DefaultFeatureCollection newCollection = new DefaultFeatureCollection();
SimpleFeatureIterator hillslopeFeatures = inHillslope.features();
while( hillslopeFeatures.hasNext() ) {
SimpleFeature hFeature = hillslopeFeatures.next();
Object netNum = hFeature.getAttribute(NetworkChannel.NETNUMNAME);
Geometry hGeometry = (Geometry) hFeature.getDefaultGeometry();
PreparedGeometry preparedHGeometry = PreparedGeometryFactory.prepare(hGeometry);
SimpleFeatureIterator netFeatures = inNetwork.features();
while( netFeatures.hasNext() ) {
SimpleFeature nFeature = netFeatures.next();
Geometry geometry = (Geometry) nFeature.getDefaultGeometry();
if (geometry.getNumGeometries() != 1) {
throw new ModelsRuntimeException("The network geometries have to be single lines.", this);
}
LineString nLine = (LineString) geometry.getGeometryN(0);
Point startPoint = nLine.getStartPoint();
if (preparedHGeometry.contains(startPoint)) {
SimpleFeature extendFeature = fExt.extendFeature(nFeature, new Object[]{netNum});
newCollection.add(extendFeature);
break;
}
}
}
inNetwork = newCollection;
}
示例9: setup
import com.vividsolutions.jts.geom.prep.PreparedGeometryFactory; //导入依赖的package包/类
@Override
public void setup(
final Configuration configuration,
final List<ColumnInterface> columnList) throws IOException
{
m_spatialIndex = new STRtree();
m_buffer = configuration.getFloat(GeoEnrichmentJob.KEY_BUFFER, 0.000001F);
final URL url = getUrl(configuration);
final ShapefileDataStoreFactory factory = new ShapefileDataStoreFactory();
final Map params = new HashMap();
params.put(ShapefileDataStoreFactory.URLP.key, url);
final DataStore dataStore = factory.createDataStore(params);
try
{
final String[] typeNames = dataStore.getTypeNames();
final SimpleFeatureSource featureSource = dataStore.getFeatureSource(typeNames[0]);
m_geometryName = featureSource.getSchema().getGeometryDescriptor().getLocalName();
final SimpleFeatureCollection featureCollection = featureSource.getFeatures();
featureCollection.accepts(new FeatureVisitor()
{
public void visit(final Feature feature)
{
final Geometry geometry = (Geometry) feature.getProperty(m_geometryName).getValue();
final PreparedGeometry preparedGeometry = PreparedGeometryFactory.prepare(geometry);
m_spatialIndex.insert(geometry.getEnvelopeInternal(), new PreparedFeature(feature, preparedGeometry));
}
}, new NullProgressListener());
}
finally
{
dataStore.dispose();
}
}
示例10: intersects
import com.vividsolutions.jts.geom.prep.PreparedGeometryFactory; //导入依赖的package包/类
public static boolean intersects(Geometry cachedGeom, Geometry g2)
{
if (intersectsCacheGeom == null
|| intersectsCacheGeom != cachedGeom) {
intersectsCacheGeom = cachedGeom;
intersectsCacheGeomPrep = PreparedGeometryFactory.prepare(cachedGeom);
}
return intersectsCacheGeomPrep.intersects(g2);
}
示例11: contains
import com.vividsolutions.jts.geom.prep.PreparedGeometryFactory; //导入依赖的package包/类
public static boolean contains(Geometry cachedGeom, Geometry g2)
{
if (containsCacheGeom == null
|| containsCacheGeom != cachedGeom) {
containsCacheGeom = cachedGeom;
containsCacheGeomPrep = PreparedGeometryFactory.prepare(cachedGeom);
// System.out.println(hitCount);
hitCount = 0;
}
hitCount++;
return containsCacheGeomPrep.contains(g2);
}
示例12: intersection
import com.vividsolutions.jts.geom.prep.PreparedGeometryFactory; //导入依赖的package包/类
public static Geometry intersection(Geometry cachedGeom, Geometry g2)
{
if (intersectionCacheGeom == null
|| intersectionCacheGeom != cachedGeom) {
intersectionCacheGeom = cachedGeom;
intersectionCacheGeomPrep = PreparedGeometryFactory.prepare(cachedGeom);
}
hitCount++;
if (! intersectionCacheGeomPrep.intersects(g2))
return g2.getFactory().createGeometryCollection(null);
if (intersectionCacheGeomPrep.contains(g2))
return g2;
return cachedGeom.intersection(g2);
}
示例13: intersectionSim
import com.vividsolutions.jts.geom.prep.PreparedGeometryFactory; //导入依赖的package包/类
public static Geometry intersectionSim(Geometry cachedGeom, Geometry g2)
{
if (intersectionCacheGeom == null
|| intersectionCacheGeom != cachedGeom) {
intersectionCacheGeom = cachedGeom;
intersectionCacheGeomPrep = PreparedGeometryFactory.prepare(cachedGeom);
}
hitCount++;
if (! intersectionCacheGeomPrep.intersects(g2))
return g2.getFactory().createGeometryCollection(null);
if (intersectionCacheGeomPrep.contains(g2))
return g2;
return intersectionSim(intersectionCacheGeomPrep, g2);
}
示例14: cacheFind
import com.vividsolutions.jts.geom.prep.PreparedGeometryFactory; //导入依赖的package包/类
private static PreparedGeometry cacheFind(Geometry g)
{
PreparedGeometry pg = cache.get(g);
if (pg == null) {
pg = PreparedGeometryFactory.prepare(g);
cache.put(g, pg);
//System.out.println("cache size = " + cache.size());
}
return pg;
}
示例15: intersectsPrep
import com.vividsolutions.jts.geom.prep.PreparedGeometryFactory; //导入依赖的package包/类
public static boolean intersectsPrep(Geometry g1, Geometry g2)
{
if (intersectsCacheGeom == null
|| intersectsCacheGeom != g1) {
intersectsCacheGeom = g1;
intersectsCacheGeomPrep = PreparedGeometryFactory.prepare(g1);
}
return intersectsCacheGeomPrep.intersects(g2);
}