Re: [JPP-Devel] Nested loop through the features of two layers

2010-07-06 Thread Stefan Steiniger
Hei,


Nils Kuhn schrieb:
> 
> By the way:
> com.vividsolutions.jts.geom.Geometry.intersects(Geometry geom) is less 
> expensive than 
> com.vividsolutions.jts.geom.Geometry.intersection(Geometry geom):

I guess the first does a point in polygon test until there is a "true".
The other one really needs to create a new geometry (after an 
intersection is found) - which should be more expensive in any case due 
to the math?

stefan

--
This SF.net email is sponsored by Sprint
What will you do first with EVO, the first 4G phone?
Visit sprint.com/first -- http://p.sf.net/sfu/sprint-com-first
___
Jump-pilot-devel mailing list
Jump-pilot-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/jump-pilot-devel


Re: [JPP-Devel] Nested loop through the features of two layers

2010-06-28 Thread Nils Kuhn
Hi,

thanks a lot Michaël and Larry.
To limit the (inner) iteration through the features of layer b to those 
features which envelopes intersect the envelope of layer a-feature 
speeds up things a lot (approx. factor 120!).
The methods 
com.vividsolutions.jump.feature.FeatureCollectionWrapper.query() and 
com.vividsolutions.jump.feature.IndexedFeatureCollection.query() seem to 
work the same way, at least there is no difference in the performance 
with my data.

By the way:
com.vividsolutions.jts.geom.Geometry.intersects(Geometry geom) is less 
expensive than 
com.vividsolutions.jts.geom.Geometry.intersection(Geometry geom):
To replace

dblAreaIntersectionTemp+=featureB.getGeometry().intersection(featureA.getGeometry()).getArea();

with

if (featureB.getGeometry().intersects(featureA.getGeometry())) {

dblAreaIntersectionTemp+=featureB.getGeometry().intersection(featureA.getGeometry()).getArea();
}

in the inner loop speeds up things twice (even though both methods, 
intersects AND intersection are applied to the intersecting geometries)!

Regards,
Nils

--
This SF.net email is sponsored by Sprint
What will you do first with EVO, the first 4G phone?
Visit sprint.com/first -- http://p.sf.net/sfu/sprint-com-first
___
Jump-pilot-devel mailing list
Jump-pilot-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/jump-pilot-devel


Re: [JPP-Devel] Nested loop through the features of two layers

2010-06-25 Thread Michaël Michaud
Hi,

//STRtree (JTS package) and IndexedFeatureCollection (jump) are your 
friends,

//You can use the index like that :

IndexedFeatureCollection ifc = new IndexedFeatureCollection(fcB, new 
STRtree());

//Then your second loop just go  through the result of the following request

List candidates = ifc.query(featureA.getEnvelopeInternal());

// candidates contains features of fcB having their envelope 
intersecting envelope of feature A in a very fast way
for (Feature candidate : candidates) {
// your test
}

//Code may contains errors, hope that's enough for you to catch the idea

Michaël


Nils Kuhn a écrit :
> Hi all,
>
> I have the following problem:
> I have two polygon-layers with many thousands of features. In layer a 
> I want to flag in an integer-field for every feature, whether the area 
> of the intersection with the polygons of layer b amounts more than 1 
> percent of the area himself.
>
> The attached code works, but the calculation would last about two 
> weeks, I think...
>
> Can anybody see a better way than my nested loop through the features 
> of both layers? I searched for a function like* 
> *com.vividsolutions.jump.feature.FeatureCollectionWrapper.query(|com.vividsolutions.jts.geom.Envelope
>  envelope|), 
> but I would like to refer a geometry instead of an envelope.
>
> Thanks for any ideas in advance.
> Regards, Nils
>
>
> 
>
> --
> ThinkGeek and WIRED's GeekDad team up for the Ultimate 
> GeekDad Father's Day Giveaway. ONE MASSIVE PRIZE to the 
> lucky parental unit.  See the prize list and enter to win: 
> http://p.sf.net/sfu/thinkgeek-promo
> 
>
> ___
> Jump-pilot-devel mailing list
> Jump-pilot-devel@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/jump-pilot-devel


--
ThinkGeek and WIRED's GeekDad team up for the Ultimate 
GeekDad Father's Day Giveaway. ONE MASSIVE PRIZE to the 
lucky parental unit.  See the prize list and enter to win: 
http://p.sf.net/sfu/thinkgeek-promo
___
Jump-pilot-devel mailing list
Jump-pilot-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/jump-pilot-devel


Re: [JPP-Devel] Nested loop through the features of two layers

2010-06-25 Thread Larry Becker
Hi Nils,

  You are on the right track with the envelope query.  Unless your polygons
are unusually overlapped (i.e. many overlap many), you should get good
performance using the results of the envelope query to feed the inner loop
of geometry intersection.

regards,
Larry




On Fri, Jun 25, 2010 at 10:53 AM, Nils Kuhn  wrote:

>  Hi all,
>
> I have the following problem:
> I have two polygon-layers with many thousands of features. In layer a I
> want to flag in an integer-field for every feature, whether the area of the
> intersection with the polygons of layer b amounts more than 1 percent of the
> area himself.
>
> The attached code works, but the calculation would last about two weeks, I
> think...
>
> Can anybody see a better way than my nested loop through the features of
> both layers? I searched for a function like* *
> com.vividsolutions.jump.feature.FeatureCollectionWrapper.query(
> com.vividsolutions.jts.geom.Envelope envelope), but I would like to refer
> a geometry instead of an envelope.
>
> Thanks for any ideas in advance.
> Regards, Nils
>
>
>
>double dblAreaIntersectionTemp;
>//layer a
>lyrA=context.getLayerManager().getLayer("LayerA");
>FeatureCollectionWrapper fcwA =
> lyrA.getFeatureCollectionWrapper();
>final Collection featuresA = fcwA.getFeatures();
>//layer b
>lyrB=context.getLayerManager().getLayer("LayerB");
>FeatureCollectionWrapper fcwB =
> lyrB.getFeatureCollectionWrapper();
>final Collection featuresB = fcwB.getFeatures();
>
>//iterate over the features of layer a
>for (Iterator iteratorA = featuresA.iterator();
> iteratorA.hasNext();) {
>Feature featureA = (Feature) iteratorA.next();
>//iterate over the features of layer b, summarize
> the intersection-areas
>dblAreaIntersectionTemp=0;
>for (Iterator iteratorB = featuresB.iterator();
> iteratorB.hasNext();) {
>Feature featureB = (Feature)
> iteratorB.next();
>
>  
> dblAreaIntersectionTemp+=featureB.getGeometry().intersection(featureA.getGeometry()).getArea();
>}
>//if the summarized intersection-area is larger than
> 1% of the area of the feature of layer a himself a flag is set to this
> feature
>if
> ((dblAreaIntersectionTemp/featureA.getGeometry().getArea())>=0.01) {
>featureA.setAttribute("flag", 1);
>}else{
>featureA.setAttribute("flag", 0);
>}
>}
>
> --
> ThinkGeek and WIRED's GeekDad team up for the Ultimate
> GeekDad Father's Day Giveaway. ONE MASSIVE PRIZE to the
> lucky parental unit.  See the prize list and enter to win:
> http://p.sf.net/sfu/thinkgeek-promo
> ___
> Jump-pilot-devel mailing list
> Jump-pilot-devel@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/jump-pilot-devel
>
>
--
ThinkGeek and WIRED's GeekDad team up for the Ultimate 
GeekDad Father's Day Giveaway. ONE MASSIVE PRIZE to the 
lucky parental unit.  See the prize list and enter to win: 
http://p.sf.net/sfu/thinkgeek-promo___
Jump-pilot-devel mailing list
Jump-pilot-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/jump-pilot-devel