Quantcast

Splitting a polygon

classic Classic list List threaded Threaded
16 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Splitting a polygon

Dipl. Inf. Carsten Eider
Hi folks,

is there an implemented way how to split a polygon by a line?

Thx Carsten

--
Mit freundlichen Grüßen / Yours faithfully
Carsten Eider

Dipl. Inf. (FH)

Kompetenzzentrum für Innovative Informationssysteme

c/o Fachhochschhule Bingen / University of applied sciences Bingen

Berlinstraße 109
55411 Bingen

Tel: +49 (0) 6721 / 409-179
Fax: +49 (0) 6721 / 409-158
email: [hidden email]
Internet: iis.fh-bingen.de


_______________________________________________
jts-devel mailing list
[hidden email]
http://lists.refractions.net/mailman/listinfo/jts-devel

eider.vcf (343 bytes) Download Attachment
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Splitting a polygon

Martin Davis
Not yet, unfortunately.  But I think uDig has something for this, and
OpenJUMP might do as well.

Dipl. Inf. Carsten Eider wrote:

> Hi folks,
>
> is there an implemented way how to split a polygon by a line?
>
> Thx Carsten
>
> _______________________________________________
> jts-devel mailing list
> [hidden email]
> http://lists.refractions.net/mailman/listinfo/jts-devel
>  

--
Martin Davis
Senior Technical Architect
Refractions Research, Inc.
(250) 383-3022

_______________________________________________
jts-devel mailing list
[hidden email]
http://lists.refractions.net/mailman/listinfo/jts-devel
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Splitting a polygon

Dipl. Inf. Carsten Eider
Hi Martin,

i have found a solution based on PostGIS, works very fine.
But it makes my solution depding on postigs, i would prefera small
jar-file to be included.

Martin Davis schrieb:

> Not yet, unfortunately.  But I think uDig has something for this, and
> OpenJUMP might do as well.
>
> Dipl. Inf. Carsten Eider wrote:
>> Hi folks,
>>
>> is there an implemented way how to split a polygon by a line?
>>
>> Thx Carsten
>>
>> _______________________________________________
>> jts-devel mailing list
>> [hidden email]
>> http://lists.refractions.net/mailman/listinfo/jts-devel
>>  
>
--
Mit freundlichen Grüßen / Yours faithfully
Carsten Eider

Dipl. Inf. (FH)

Kompetenzzentrum für Innovative Informationssysteme

c/o Fachhochschhule Bingen / University of applied sciences Bingen

Berlinstraße 109
55411 Bingen

Tel: +49 (0) 6721 / 409-179
Fax: +49 (0) 6721 / 409-158
email: [hidden email]
Internet: iis.fh-bingen.de


_______________________________________________
jts-devel mailing list
[hidden email]
http://lists.refractions.net/mailman/listinfo/jts-devel

eider.vcf (343 bytes) Download Attachment
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Splitting a polygon

Martin Davis
Oh - what's your PostGIS solution?   Do they have a polygon-splitting
method?

And I agree - it would be nicer to have this in JTS...

Dipl. Inf. Carsten Eider wrote:

> Hi Martin,
>
> i have found a solution based on PostGIS, works very fine.
> But it makes my solution depding on postigs, i would prefera small
> jar-file to be included.
>
> Martin Davis schrieb:
>> Not yet, unfortunately.  But I think uDig has something for this, and
>> OpenJUMP might do as well.
>>
>> Dipl. Inf. Carsten Eider wrote:
>>> Hi folks,
>>>
>>> is there an implemented way how to split a polygon by a line?
>>>
>>> Thx Carsten
>>>
>>> _______________________________________________
>>> jts-devel mailing list
>>> [hidden email]
>>> http://lists.refractions.net/mailman/listinfo/jts-devel
>>>  
>>
>
> _______________________________________________
> jts-devel mailing list
> [hidden email]
> http://lists.refractions.net/mailman/listinfo/jts-devel
>  

--
Martin Davis
Senior Technical Architect
Refractions Research, Inc.
(250) 383-3022

_______________________________________________
jts-devel mailing list
[hidden email]
http://lists.refractions.net/mailman/listinfo/jts-devel
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Splitting a polygon

Dipl. Inf. Carsten Eider
Look at this solution, it works great for me

http://postgis.refractions.net/pipermail/postgis-users/2008-May/019904.html

Martin Davis schrieb:

> Oh - what's your PostGIS solution?   Do they have a polygon-splitting
> method?
>
> And I agree - it would be nicer to have this in JTS...
>
> Dipl. Inf. Carsten Eider wrote:
>> Hi Martin,
>>
>> i have found a solution based on PostGIS, works very fine.
>> But it makes my solution depding on postigs, i would prefera small
>> jar-file to be included.
>>
>> Martin Davis schrieb:
>>> Not yet, unfortunately.  But I think uDig has something for this,
>>> and OpenJUMP might do as well.
>>>
>>> Dipl. Inf. Carsten Eider wrote:
>>>> Hi folks,
>>>>
>>>> is there an implemented way how to split a polygon by a line?
>>>>
>>>> Thx Carsten
>>>>
>>>> _______________________________________________
>>>> jts-devel mailing list
>>>> [hidden email]
>>>> http://lists.refractions.net/mailman/listinfo/jts-devel
>>>>  
>>>
>>
>> _______________________________________________
>> jts-devel mailing list
>> [hidden email]
>> http://lists.refractions.net/mailman/listinfo/jts-devel
>>  
>
--
Mit freundlichen Grüßen / Yours faithfully
Carsten Eider

Dipl. Inf. (FH)

Kompetenzzentrum für Innovative Informationssysteme

c/o Fachhochschhule Bingen / University of applied sciences Bingen

Berlinstraße 109
55411 Bingen

Tel: +49 (0) 6721 / 409-179
Fax: +49 (0) 6721 / 409-158
email: [hidden email]
Internet: iis.fh-bingen.de


_______________________________________________
jts-devel mailing list
[hidden email]
http://lists.refractions.net/mailman/listinfo/jts-devel

eider.vcf (343 bytes) Download Attachment
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Splitting a polygon

bobzien@bluewin.ch
In reply to this post by Dipl. Inf. Carsten Eider

Stefan Steiniger wrote:
>>
>> Not yet, unfortunately.  But I think uDig has something for this, and
>> OpenJUMP might do as well.
>
>yep. OpenJUMP has a tool that splits polygons - but it does not
>recognize holes

Just as a remark:
The OpenJUMP tool does not check the input on meaningfulness - and as a consequence it might return invalid
geometries.

For example try splitting the following geometries:
POLYGON((0 0,10 0,5 7,0 0))
LINESTRING(0 4,5 4)

To solve this issue (as well as some including holes) the plugin has to assure two things:
1. the linestring intersects each ring of the polygon an even number of times.
2. if the linestring intersects an interior ring, then it has to intersect the exterior ring.

I'm not sure if this covers all issues, but it is a first step :-)

Matthias



_______________________________________________
jts-devel mailing list
[hidden email]
http://lists.refractions.net/mailman/listinfo/jts-devel
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Splitting a polygon

Martin Davis
In reply to this post by Dipl. Inf. Carsten Eider
Ah, yes, I remember Kevin's clever solution now.  Good that it works for
you...

You could do exactly the same in JTS (in fact the PostGIS solution uses
GEOS, which is basically JTS).  Use MCIndexNoder to node the polygon and
linestring together, Polygonizer to polygonize the noded edges, and then
PointLocater to determine which of the resultant polygons correspond to
the input polygon.

The one thing this won't tell you is which side of the line the
resultants are on - you'll have to determine this in some other way.

Dipl. Inf. Carsten Eider wrote:

> Look at this solution, it works great for me
>
> http://postgis.refractions.net/pipermail/postgis-users/2008-May/019904.html 
>
>
> Martin Davis schrieb:
>> Oh - what's your PostGIS solution?   Do they have a polygon-splitting
>> method?
>>
>> And I agree - it would be nicer to have this in JTS...
>>
>> Dipl. Inf. Carsten Eider wrote:
>>> Hi Martin,
>>>
>>> i have found a solution based on PostGIS, works very fine.
>>> But it makes my solution depding on postigs, i would prefera small
>>> jar-file to be included.
>>>
>>> Martin Davis schrieb:
>>>> Not yet, unfortunately.  But I think uDig has something for this,
>>>> and OpenJUMP might do as well.
>>>>
>>>> Dipl. Inf. Carsten Eider wrote:
>>>>> Hi folks,
>>>>>
>>>>> is there an implemented way how to split a polygon by a line?
>>>>>
>>>>> Thx Carsten
>>>>>
>>>>> _______________________________________________
>>>>> jts-devel mailing list
>>>>> [hidden email]
>>>>> http://lists.refractions.net/mailman/listinfo/jts-devel
>>>>>  
>>>>
>>>
>>> _______________________________________________
>>> jts-devel mailing list
>>> [hidden email]
>>> http://lists.refractions.net/mailman/listinfo/jts-devel
>>>  
>>
>
> _______________________________________________
> jts-devel mailing list
> [hidden email]
> http://lists.refractions.net/mailman/listinfo/jts-devel
>  

--
Martin Davis
Senior Technical Architect
Refractions Research, Inc.
(250) 383-3022

_______________________________________________
jts-devel mailing list
[hidden email]
http://lists.refractions.net/mailman/listinfo/jts-devel
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Splitting a polygon

Dipl. Inf. Carsten Eider
Hi Martin,

could you just give me a workig code-snippet for it?
What do you mean with your sentence

> The one thing this won't tell you is which side of the line the
> resultants are on - you'll have to determine this in some other way.

Quoting Martin Davis <[hidden email]>:

> Ah, yes, I remember Kevin's clever solution now.  Good that it works
> for you... You could do exactly the same in JTS (in fact the PostGIS
> solution uses GEOS, which is basically JTS).  Use MCIndexNoder to node
> the polygon and linestring together, Polygonizer to polygonize the
> noded edges, and then PointLocater to determine which of the resultant
> polygons correspond to the input polygon.
>
> The one thing this won't tell you is which side of the line the
> resultants are on - you'll have to determine this in some other way.
>
> Dipl. Inf. Carsten Eider wrote:
>> Look at this solution, it works great for me
>>
>> http://postgis.refractions.net/pipermail/postgis-users/2008-May/019904.html 
>>  Martin Davis schrieb:
>>> Oh - what's your PostGIS solution?   Do they have a  
>>> polygon-splitting method?
>>>
>>> And I agree - it would be nicer to have this in JTS...
>>>
>>> Dipl. Inf. Carsten Eider wrote:
>>>> Hi Martin,
>>>>
>>>> i have found a solution based on PostGIS, works very fine.
>>>> But it makes my solution depding on postigs, i would prefera  
>>>> small jar-file to be included.
>>>>
>>>> Martin Davis schrieb:
>>>>> Not yet, unfortunately.  But I think uDig has something for  
>>>>> this, and OpenJUMP might do as well.
>>>>>
>>>>> Dipl. Inf. Carsten Eider wrote:
>>>>>> Hi folks,
>>>>>>
>>>>>> is there an implemented way how to split a polygon by a line?
>>>>>>
>>>>>> Thx Carsten
>>>>>>
>>>>>> _______________________________________________
>>>>>> jts-devel mailing list
>>>>>> [hidden email]
>>>>>> http://lists.refractions.net/mailman/listinfo/jts-devel
>>>>>>
>>>>>
>>>>
>>>> _______________________________________________
>>>> jts-devel mailing list
>>>> [hidden email]
>>>> http://lists.refractions.net/mailman/listinfo/jts-devel
>>>>
>>>
>>
>> _______________________________________________
>> jts-devel mailing list
>> [hidden email]
>> http://lists.refractions.net/mailman/listinfo/jts-devel
>>
>
> --
> Martin Davis
> Senior Technical Architect
> Refractions Research, Inc.
> (250) 383-3022
>
> _______________________________________________
> jts-devel mailing list
> [hidden email]
> http://lists.refractions.net/mailman/listinfo/jts-devel


_______________________________________________
jts-devel mailing list
[hidden email]
http://lists.refractions.net/mailman/listinfo/jts-devel
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Splitting a polygon

Martin Davis
Unfortunately I don't have time to do this at the moment - probably not
for a month at least.

What the last sentence means is that if you say split a circle with a
line you will get half-circles.  If you only want the one which lies on
a particular side of the line you'd have to figure that out for
yourself.  Of course, if you are happy getting all the resultants then
this is not an issue.

[hidden email] wrote:

> Hi Martin,
>
> could you just give me a workig code-snippet for it?
> What do you mean with your sentence
>
>> The one thing this won't tell you is which side of the line the
>> resultants are on - you'll have to determine this in some other way.
>
> Quoting Martin Davis <[hidden email]>:
>
>> Ah, yes, I remember Kevin's clever solution now.  Good that it works
>> for you... You could do exactly the same in JTS (in fact the PostGIS
>> solution uses GEOS, which is basically JTS).  Use MCIndexNoder to node
>> the polygon and linestring together, Polygonizer to polygonize the
>> noded edges, and then PointLocater to determine which of the resultant
>> polygons correspond to the input polygon.
>>
>> The one thing this won't tell you is which side of the line the
>> resultants are on - you'll have to determine this in some other way.
>>
>> Dipl. Inf. Carsten Eider wrote:
>>> Look at this solution, it works great for me
>>>
>>> http://postgis.refractions.net/pipermail/postgis-users/2008-May/019904.html 
>>>  Martin Davis schrieb:
>>>> Oh - what's your PostGIS solution?   Do they have a  
>>>> polygon-splitting method?
>>>>
>>>> And I agree - it would be nicer to have this in JTS...
>>>>
>>>> Dipl. Inf. Carsten Eider wrote:
>>>>> Hi Martin,
>>>>>
>>>>> i have found a solution based on PostGIS, works very fine.
>>>>> But it makes my solution depding on postigs, i would prefera  
>>>>> small jar-file to be included.
>>>>>
>>>>> Martin Davis schrieb:
>>>>>> Not yet, unfortunately.  But I think uDig has something for  
>>>>>> this, and OpenJUMP might do as well.
>>>>>>
>>>>>> Dipl. Inf. Carsten Eider wrote:
>>>>>>> Hi folks,
>>>>>>>
>>>>>>> is there an implemented way how to split a polygon by a line?
>>>>>>>
>>>>>>> Thx Carsten
>>>>>>>
>>>>>>> _______________________________________________
>>>>>>> jts-devel mailing list
>>>>>>> [hidden email]
>>>>>>> http://lists.refractions.net/mailman/listinfo/jts-devel
>>>>>>>
>>>>>>
>>>>>
>>>>> _______________________________________________
>>>>> jts-devel mailing list
>>>>> [hidden email]
>>>>> http://lists.refractions.net/mailman/listinfo/jts-devel
>>>>>
>>>>
>>>
>>> _______________________________________________
>>> jts-devel mailing list
>>> [hidden email]
>>> http://lists.refractions.net/mailman/listinfo/jts-devel
>>>
>>
>> --
>> Martin Davis
>> Senior Technical Architect
>> Refractions Research, Inc.
>> (250) 383-3022
>>
>> _______________________________________________
>> jts-devel mailing list
>> [hidden email]
>> http://lists.refractions.net/mailman/listinfo/jts-devel
>
>
>

--
Martin Davis
Senior Technical Architect
Refractions Research, Inc.
(250) 383-3022

_______________________________________________
jts-devel mailing list
[hidden email]
http://lists.refractions.net/mailman/listinfo/jts-devel
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Splitting a polygon

Dipl. Inf. Carsten Eider
i will have a look on  it and whenever i find a solution i will share  
with everyone  who needs it
Quoting Martin Davis <[hidden email]>:

> Unfortunately I don't have time to do this at the moment - probably not
> for a month at least.
>
> What the last sentence means is that if you say split a circle with a
> line you will get half-circles.  If you only want the one which lies on
> a particular side of the line you'd have to figure that out for
> yourself.  Of course, if you are happy getting all the resultants then
> this is not an issue.
>
> [hidden email] wrote:
>> Hi Martin,
>>
>> could you just give me a workig code-snippet for it?
>> What do you mean with your sentence
>>
>>> The one thing this won't tell you is which side of the line the
>>> resultants are on - you'll have to determine this in some other way.
>>
>> Quoting Martin Davis <[hidden email]>:
>>
>>> Ah, yes, I remember Kevin's clever solution now.  Good that it works
>>> for you... You could do exactly the same in JTS (in fact the PostGIS
>>> solution uses GEOS, which is basically JTS).  Use MCIndexNoder to node
>>> the polygon and linestring together, Polygonizer to polygonize the
>>> noded edges, and then PointLocater to determine which of the resultant
>>> polygons correspond to the input polygon.
>>>
>>> The one thing this won't tell you is which side of the line the
>>> resultants are on - you'll have to determine this in some other way.
>>>
>>> Dipl. Inf. Carsten Eider wrote:
>>>> Look at this solution, it works great for me
>>>>
>>>> http://postgis.refractions.net/pipermail/postgis-users/2008-May/019904.html Martin Davis  
>>>> schrieb:
>>>>> Oh - what's your PostGIS solution?   Do they have a    
>>>>> polygon-splitting method?
>>>>>
>>>>> And I agree - it would be nicer to have this in JTS...
>>>>>
>>>>> Dipl. Inf. Carsten Eider wrote:
>>>>>> Hi Martin,
>>>>>>
>>>>>> i have found a solution based on PostGIS, works very fine.
>>>>>> But it makes my solution depding on postigs, i would prefera    
>>>>>> small jar-file to be included.
>>>>>>
>>>>>> Martin Davis schrieb:
>>>>>>> Not yet, unfortunately.  But I think uDig has something for    
>>>>>>> this, and OpenJUMP might do as well.
>>>>>>>
>>>>>>> Dipl. Inf. Carsten Eider wrote:
>>>>>>>> Hi folks,
>>>>>>>>
>>>>>>>> is there an implemented way how to split a polygon by a line?
>>>>>>>>
>>>>>>>> Thx Carsten
>>>>>>>>
>>>>>>>> _______________________________________________
>>>>>>>> jts-devel mailing list
>>>>>>>> [hidden email]
>>>>>>>> http://lists.refractions.net/mailman/listinfo/jts-devel
>>>>>>>>
>>>>>>>
>>>>>>
>>>>>> _______________________________________________
>>>>>> jts-devel mailing list
>>>>>> [hidden email]
>>>>>> http://lists.refractions.net/mailman/listinfo/jts-devel
>>>>>>
>>>>>
>>>>
>>>> _______________________________________________
>>>> jts-devel mailing list
>>>> [hidden email]
>>>> http://lists.refractions.net/mailman/listinfo/jts-devel
>>>>
>>>
>>> --
>>> Martin Davis
>>> Senior Technical Architect
>>> Refractions Research, Inc.
>>> (250) 383-3022
>>>
>>> _______________________________________________
>>> jts-devel mailing list
>>> [hidden email]
>>> http://lists.refractions.net/mailman/listinfo/jts-devel
>>
>>
>>
>
> --
> Martin Davis
> Senior Technical Architect
> Refractions Research, Inc.
> (250) 383-3022
>
> _______________________________________________
> jts-devel mailing list
> [hidden email]
> http://lists.refractions.net/mailman/listinfo/jts-devel


_______________________________________________
jts-devel mailing list
[hidden email]
http://lists.refractions.net/mailman/listinfo/jts-devel
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Splitting a polygon

Dipl. Inf. Carsten Eider
Hi folks,

i tried to use Martin's solution, but i can't get it working
I want to try to split a square with a side-length of 10 by it's
diagonal line from the lower left to the upper right

I can get MonotoneChains out of the MCIndexnoder, but don't know what to
do later on!

Any ideas?
Carsten

Here my code snippets:

private static String split2(Polygon p, LineString l) {
        SegmentIntersectionDetector _intersector = new
SegmentIntersectionDetector(new RobustLineIntersector());
        //_intersector.setFindProper(true);
        _intersector.setFindAllIntersectionTypes(true);
        MCIndexNoder _mci = new MCIndexNoder();
        _mci.setSegmentIntersector(_intersector);
        NodedSegmentString _pseg = new
NodedSegmentString(p.getCoordinates(), p);
        System.out.println(_pseg + "/" + _pseg.isClosed() + "/" +
_pseg.size());
        NodedSegmentString _lseg = new
NodedSegmentString(l.getCoordinates(), l);
        System.out.println(_lseg + "/" + _lseg.isClosed() + "/" +
_lseg.size());
        Vector _v = new Vector(2);
        _v.add(_lseg);
        _v.add(_pseg);
        _mci.computeNodes(_v);
        GeometryFactory _fac = new GeometryFactory();
        Polygonizer _polygonizer = new Polygonizer();
        for (Object o : _mci.getNodedSubstrings()) {
            NodedSegmentString _o = (NodedSegmentString) o;
            System.out.println(_o);
            for (Coordinate _coor : _o.getCoordinates()) {
                System.out.print(_coor);
            }
            System.out.println("");
        }
        for (Object o : _mci.getMonotoneChains()) {
            MonotoneChain _mtc = (MonotoneChain) o;
            System.out.println(_mtc);
            System.out.println(_mtc.getCoordinates().length);
            for (Coordinate _coor : _mtc.getCoordinates()) {
                System.out.print(_coor);
            }
            System.out.println("");
        }
        return (null);
    }

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) throws Exception {
        // TODO code application logic here

        // "LINESTRING (0 1,2 -2,4 0,5 11,8 8,11 8,10 0)"
        LineString _l = (LineString) new WKTReader().read("LINESTRING
(-1 -1,11 11)");
        Coordinate[] coordinates = new Coordinate[]{
            new Coordinate(0, 0), new Coordinate(10, 0),
            new Coordinate(10, 10), new Coordinate(0, 10), new
Coordinate(0, 0)
        };
        Polygon p1 = new GeometryFactory().createPolygon(new
GeometryFactory().createLinearRing(coordinates), null);
        //System.out.println(TestSplit.pgSplit(p1, _l));
        System.out.println("2:" + TestSplit.split2(p1, _l));
    }

System outs are:

run-main:
com.vividsolutions.jts.noding.NodedSegmentString@3a6727/true/5
com.vividsolutions.jts.noding.NodedSegmentString@4a65e0/false/2
com.vividsolutions.jts.noding.NodedSegmentString@1ca318a       //this is
my line
(-1.0, -1.0, NaN)(11.0, 11.0, NaN)
com.vividsolutions.jts.noding.NodedSegmentString@17a8913
(0.0, 0.0, NaN)(10.0, 0.0, NaN)(10.0, 10.0, NaN)(0.0, 10.0, NaN)(0.0,
0.0, NaN)  //this is my polygon
com.vividsolutions.jts.index.chain.MonotoneChain@1bd747e
2
(-1.0, -1.0, NaN)(11.0, 11.0, NaN)                                      
   //this is the line
com.vividsolutions.jts.index.chain.MonotoneChain@12b3374
3
(0.0, 0.0, NaN)(10.0, 0.0, NaN)(10.0, 10.0, NaN)                    
//upper border of my polygon
com.vividsolutions.jts.index.chain.MonotoneChain@13f3789
2
(10.0, 10.0, NaN)(0.0, 10.0, NaN)                                      
      //right line of my polygon
com.vividsolutions.jts.index.chain.MonotoneChain@1571886    // lower
side of my polygon
2
(0.0, 10.0, NaN)(0.0, 0.0, NaN)
2:null


[hidden email] schrieb:

> i will have a look on  it and whenever i find a solution i will share
> with everyone  who needs it
> Quoting Martin Davis <[hidden email]>:
>
>> Unfortunately I don't have time to do this at the moment - probably not
>> for a month at least.
>>
>> What the last sentence means is that if you say split a circle with a
>> line you will get half-circles.  If you only want the one which lies on
>> a particular side of the line you'd have to figure that out for
>> yourself.  Of course, if you are happy getting all the resultants then
>> this is not an issue.
>>
>> [hidden email] wrote:
>>> Hi Martin,
>>>
>>> could you just give me a workig code-snippet for it?
>>> What do you mean with your sentence
>>>
>>>> The one thing this won't tell you is which side of the line the
>>>> resultants are on - you'll have to determine this in some other way.
>>>
>>> Quoting Martin Davis <[hidden email]>:
>>>
>>>> Ah, yes, I remember Kevin's clever solution now.  Good that it works
>>>> for you... You could do exactly the same in JTS (in fact the PostGIS
>>>> solution uses GEOS, which is basically JTS).  Use MCIndexNoder to node
>>>> the polygon and linestring together, Polygonizer to polygonize the
>>>> noded edges, and then PointLocater to determine which of the resultant
>>>> polygons correspond to the input polygon.
>>>>
>>>> The one thing this won't tell you is which side of the line the
>>>> resultants are on - you'll have to determine this in some other way.
>>>>
>>>> Dipl. Inf. Carsten Eider wrote:
>>>>> Look at this solution, it works great for me
>>>>>
>>>>> http://postgis.refractions.net/pipermail/postgis-users/2008-May/019904.html 
>>>>> Martin Davis  schrieb:
>>>>>> Oh - what's your PostGIS solution?   Do they have a  
>>>>>> polygon-splitting method?
>>>>>>
>>>>>> And I agree - it would be nicer to have this in JTS...
>>>>>>
>>>>>> Dipl. Inf. Carsten Eider wrote:
>>>>>>> Hi Martin,
>>>>>>>
>>>>>>> i have found a solution based on PostGIS, works very fine.
>>>>>>> But it makes my solution depding on postigs, i would prefera  
>>>>>>> small jar-file to be included.
>>>>>>>
>>>>>>> Martin Davis schrieb:
>>>>>>>> Not yet, unfortunately.  But I think uDig has something for  
>>>>>>>> this, and OpenJUMP might do as well.
>>>>>>>>
>>>>>>>> Dipl. Inf. Carsten Eider wrote:
>>>>>>>>> Hi folks,
>>>>>>>>>
>>>>>>>>> is there an implemented way how to split a polygon by a line?
>>>>>>>>>
>>>>>>>>> Thx Carsten
>>>>>>>>>
>>>>>>>>> _______________________________________________
>>>>>>>>> jts-devel mailing list
>>>>>>>>> [hidden email]
>>>>>>>>> http://lists.refractions.net/mailman/listinfo/jts-devel
>>>>>>>>>
>>>>>>>>
>>>>>>>
>>>>>>> _______________________________________________
>>>>>>> jts-devel mailing list
>>>>>>> [hidden email]
>>>>>>> http://lists.refractions.net/mailman/listinfo/jts-devel
>>>>>>>
>>>>>>
>>>>>
>>>>> _______________________________________________
>>>>> jts-devel mailing list
>>>>> [hidden email]
>>>>> http://lists.refractions.net/mailman/listinfo/jts-devel
>>>>>
>>>>
>>>> --
>>>> Martin Davis
>>>> Senior Technical Architect
>>>> Refractions Research, Inc.
>>>> (250) 383-3022
>>>>
>>>> _______________________________________________
>>>> jts-devel mailing list
>>>> [hidden email]
>>>> http://lists.refractions.net/mailman/listinfo/jts-devel
>>>
>>>
>>>
>>
>> --
>> Martin Davis
>> Senior Technical Architect
>> Refractions Research, Inc.
>> (250) 383-3022
>>
>> _______________________________________________
>> jts-devel mailing list
>> [hidden email]
>> http://lists.refractions.net/mailman/listinfo/jts-devel
>
>
> _______________________________________________
> jts-devel mailing list
> [hidden email]
> http://lists.refractions.net/mailman/listinfo/jts-devel
>
--
Mit freundlichen Grüßen / Yours faithfully
Carsten Eider

Dipl. Inf. (FH)

Kompetenzzentrum für Innovative Informationssysteme

c/o Fachhochschhule Bingen / University of applied sciences Bingen

Berlinstraße 109
55411 Bingen

Tel: +49 (0) 6721 / 409-179
Fax: +49 (0) 6721 / 409-158
email: [hidden email]
Internet: iis.fh-bingen.de


_______________________________________________
jts-devel mailing list
[hidden email]
http://lists.refractions.net/mailman/listinfo/jts-devel

eider.vcf (472 bytes) Download Attachment
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Splitting a polygon

Dipl. Inf. Carsten Eider
Hi list,

i am getting sick while trying to resolve my problem of splitting a polygon(assumd to have no wholes within),
it is driving me crazy! martin gave the hint:

"Use MCIndexNoder to node the polygon and linestring together, Polygonizer to polygonize the noded edges, and then PointLocater to determine which of the resultant  polygons correspond to the input polygon. "

Here is my non working attempt

Polygon p, LineString l;

//Use MCIndexNoder
//Setup intersector any classes implementing SegmentIntersector (<a href="cid:part1.06080109.04040502@fh-bingen.de" title="class in com.vividsolutions.jts.noding">InteriorIntersectionFinder, <a href="cid:part2.01090803.02020901@fh-bingen.de" title="class in com.vividsolutions.jts.noding">IntersectionAdder, <a href="cid:part3.07090708.09090105@fh-bingen.de" title="class in com.vividsolutions.jts.noding">IntersectionFinderAdder, <a href="cid:part4.09020607.05010504@fh-bingen.de" title="class in com.vividsolutions.jts.geom.prep">LineIntersectionAdder, <a href="cid:part5.01000302.05080102@fh-bingen.de" title="class in com.vividsolutions.jts.noding">SegmentIntersectionDetector) have been tested!
SegmentIntersectionDetector _intersector = new SegmentIntersectionDetector(new RobustLineIntersector());
_intersector.setFindProper(true);
_intersector.setFindAllIntersectionTypes(true);

//Wouldn't it be better to setup intersector within the constructor?
MCIndexNoder _mci = new MCIndexNoder();
_mci.setSegmentIntersector(_intersector);
// Add my polygon and my LineString
NodedSegmentString _pseg = new NodedSegmentString(p.getCoordinates(), null);
NodedSegmentString _lseg = new NodedSegmentString(l.getCoordinates(), null);
Vector<NodedSegmentString> _v = new Vector<NodedSegmentString>();
//order of adding doesn't alter result
_v.add(_pseg);
_v.add(_lseg);
//lets compute the nodes, whatever this does mean!
_mci.computeNodes(_v);
//here is my polygonizer
Polygonizer _polygonizer = new Polygonizer();
//let's add thsi monotonechains, whatever they mean!
for (Object o : _mci.getMonotoneChains()) {
            MonotoneChain _mtc = (MonotoneChain) o;
             //Convert chain to a linestring, is thsi correct?
            LineString _line = _fac.createLineString(_mtc.getCoordinates());
            System.out.println(_line);
            _polygonizer.add(_line);
}
//Here are my hopefully correct poylgons!
Collection<Polygon> _polygons = _polygonizer.getPolygons();
for (Polygon _p : _polygons) {
           /System.out.println(_p);
}

Example 1:
l=LINESTRING (0 0,4 5, 5 4,10 10);
p=POLYGON(0 0,10 0,10 10 ,0 10, 3 8,0 0)
pgsql:<polygon>POLYGON ((10 10, 10 0, 0 0, 4 5, 5 4, 10 10))</polygon><polygon>POLYGON ((0 0, 3 8, 0 10, 10 10, 5 4, 4 5, 0 0))</polygon>
jts:<polygon>POLYGON ((5 4, 4 5, 0 0, 3 8, 0 10, 10 10, 5 4))</polygon><polygon>POLYGON ((0 0, 4 5, 5 4, 10 10, 10 0, 0 0))</polygon>

jts==pgsql==>Correct GREAT

Example 2:
l=LINESTRING (-1 -1,4 5, 5 4,11 11);
p=POLYGON(0 0,10 0,10 10 ,0 10, 3 8,0 0)
pgsql:<polygon>POLYGON ((10 9.83333333333333, 10 0, 0 0, 0.136363636363636 0.363636363636364, 4 5, 5 4, 10 9.83333333333333))</polygon><polygon>POLYGON ((0.136363636363636 0.363636363636364, 3 8, 0 10, 10 10, 10 9.83333333333333, 5 4, 4 5, 0.136363636363636 0.363636363636364))</polygon>
jts:<polygon>POLYGON ((0 0, 3 8, 0 10, 10 10, 10 0, 0 0))</polygon>

jts!=pgsql, damn where is my second polygon as expected? why do i get just my original polygon?


Example 3
l=LINESTRING (0 0,4 5, 5 4,10 10,10 6,0 6)
p=POLYGON(0 0,10 0,10 10 ,0 10, 3 8,0 0)
pgsql:<polygon>POLYGON ((10 6, 10 0, 0 0, 4 5, 5 4, 6.66666666666667 6, 10 6))</polygon><polygon>POLYGON ((10 10, 10 6, 6.66666666666667 6, 10 10))</polygon><polygon>POLYGON ((2.25 6, 3 8, 0 10, 10 10, 6.66666666666667 6, 2.25 6))</polygon><polygon>POLYGON ((0 0, 2.25 6, 6.66666666666667 6, 5 4, 4 5, 0 0))</polygon>
jts:<polygon>POLYGON ((5 4, 4 5, 0 0, 3 8, 0 10, 10 10, 5 4))</polygon><polygon>POLYGON ((0 0, 4 5, 5 4, 10 10, 10 0, 0 0))</polygon>

jts!=pgsql, why the hell are there only two polygons left? where are the other two as expected?


Any suggestions are very appreciated!
Maybe i should offer a reward of a box of good german beer !

TIA Carsten
--
Mit freundlichen Grüßen / Yours faithfully
Carsten Eider

Dipl. Inf. (FH)

Kompetenzzentrum für Innovative Informationssysteme

c/o Fachhochschhule Bingen / University of applied sciences Bingen

Berlinstraße 109
55411 Bingen

Tel: +49 (0) 6721 / 409-179
Fax: +49 (0) 6721 / 409-158
email: [hidden email]
Internet: iis.fh-bingen.de 

InteriorIntersectionFinder <SCRIPT type="text/javascript"> function windowTitle() { parent.document.title="InteriorIntersectionFinder"; } </SCRIPT>

com.vividsolutions.jts.noding
Class InteriorIntersectionFinder

java.lang.Object
  extended bycom.vividsolutions.jts.noding.InteriorIntersectionFinder
All Implemented Interfaces:
SegmentIntersector

public class InteriorIntersectionFinder
extends java.lang.Object
implements SegmentIntersector

Finds an interior intersection in a set of SegmentStrings, if one exists. Only the first intersection found is reported.

Version:
1.7

Constructor Summary
InteriorIntersectionFinder(LineIntersector li)
          Creates an intersection finder which finds an interior intersection if one exists
 
Method Summary
 Coordinate getInteriorIntersection()
          Gets the computed location of the intersection.
 Coordinate[] getIntersectionSegments()
          Gets the endpoints of the intersecting segments.
 boolean hasIntersection()
          Tests whether an intersection was found.
 boolean isDone()
          Reports whether the client of this class needs to continue testing all intersections in an arrangement.
 void <A HREF="../../../../com/vividsolutions/jts/noding/InteriorIntersectionFinder.html#processIntersections(com.vividsolutions.jts.noding.SegmentString, int, com.vividsolutions.jts.noding.SegmentString, int)">processIntersections(SegmentString e0, int segIndex0, SegmentString e1, int segIndex1)
          This method is called by clients of the SegmentIntersector class to process intersections for two segments of the SegmentStrings being intersected.
 void setCheckEndSegmentsOnly(boolean isCheckEndSegmentsOnly)
          Sets whether only end segments should be tested for interior intersection.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

InteriorIntersectionFinder

public InteriorIntersectionFinder(LineIntersector li)
Creates an intersection finder which finds an interior intersection if one exists

Parameters:
li - the LineIntersector to use
Method Detail

setCheckEndSegmentsOnly

public void setCheckEndSegmentsOnly(boolean isCheckEndSegmentsOnly)
Sets whether only end segments should be tested for interior intersection. This is a performance optimization that may be used if the segments have been previously noded by an appropriate algorithm. It may be known that any potential noding failures will occur only in end segments.

Parameters:
isCheckEndSegmentsOnly - whether to test only end segments

hasIntersection

public boolean hasIntersection()
Tests whether an intersection was found.

Returns:
true if an intersection was found

getInteriorIntersection

public Coordinate getInteriorIntersection()
Gets the computed location of the intersection. Due to round-off, the location may not be exact.

Returns:
the coordinate for the intersection location

getIntersectionSegments

public Coordinate[] getIntersectionSegments()
Gets the endpoints of the intersecting segments.

Returns:
an array of the segment endpoints (p00, p01, p10, p11)

processIntersections

public void processIntersections(SegmentString e0,
                                 int segIndex0,
                                 SegmentString e1,
                                 int segIndex1)
This method is called by clients of the SegmentIntersector class to process intersections for two segments of the SegmentStrings being intersected. Note that some clients (such as MonotoneChains) may optimize away this call for segment pairs which they have determined do not intersect (e.g. by an disjoint envelope test).

Specified by:
<A HREF="../../../../com/vividsolutions/jts/noding/SegmentIntersector.html#processIntersections(com.vividsolutions.jts.noding.SegmentString, int, com.vividsolutions.jts.noding.SegmentString, int)">processIntersections in interface SegmentIntersector

isDone

public boolean isDone()
Description copied from interface: SegmentIntersector
Reports whether the client of this class needs to continue testing all intersections in an arrangement.

Specified by:
isDone in interface SegmentIntersector
Returns:
true if there is no need to continue testing segments



IntersectionAdder <SCRIPT type="text/javascript"> function windowTitle() { parent.document.title="IntersectionAdder"; } </SCRIPT>

com.vividsolutions.jts.noding
Class IntersectionAdder

java.lang.Object
  extended bycom.vividsolutions.jts.noding.IntersectionAdder
All Implemented Interfaces:
SegmentIntersector

public class IntersectionAdder
extends java.lang.Object
implements SegmentIntersector

Computes the intersections between two line segments in SegmentStrings and adds them to each string. The SegmentIntersector is passed to a Noder. The addIntersections method is called whenever the Noder detects that two SegmentStrings might intersect. This class is an example of the Strategy pattern.

Version:
1.7

Field Summary
 int numInteriorIntersections
           
 int numIntersections
           
 int numProperIntersections
           
 int numTests
           
 
Constructor Summary
IntersectionAdder(LineIntersector li)
           
 
Method Summary
 LineIntersector getLineIntersector()
           
 Coordinate getProperIntersectionPoint()
           
 boolean hasInteriorIntersection()
          An interior intersection is an intersection which is in the interior of some segment.
 boolean hasIntersection()
           
 boolean hasProperInteriorIntersection()
          A proper interior intersection is a proper intersection which is not contained in the set of boundary nodes set for this SegmentIntersector.
 boolean hasProperIntersection()
          A proper intersection is an intersection which is interior to at least two line segments.
static boolean <A HREF="../../../../com/vividsolutions/jts/noding/IntersectionAdder.html#isAdjacentSegments(int, int)">isAdjacentSegments(int i1, int i2)
           
 boolean isDone()
          Always process all intersections
 void <A HREF="../../../../com/vividsolutions/jts/noding/IntersectionAdder.html#processIntersections(com.vividsolutions.jts.noding.SegmentString, int, com.vividsolutions.jts.noding.SegmentString, int)">processIntersections(SegmentString e0, int segIndex0, SegmentString e1, int segIndex1)
          This method is called by clients of the SegmentIntersector class to process intersections for two segments of the SegmentStrings being intersected.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

numIntersections

public int numIntersections

numInteriorIntersections

public int numInteriorIntersections

numProperIntersections

public int numProperIntersections

numTests

public int numTests
Constructor Detail

IntersectionAdder

public IntersectionAdder(LineIntersector li)
Method Detail

isAdjacentSegments

public static boolean isAdjacentSegments(int i1,
                                         int i2)

getLineIntersector

public LineIntersector getLineIntersector()

getProperIntersectionPoint

public Coordinate getProperIntersectionPoint()
Returns:
the proper intersection point, or null if none was found

hasIntersection

public boolean hasIntersection()

hasProperIntersection

public boolean hasProperIntersection()
A proper intersection is an intersection which is interior to at least two line segments. Note that a proper intersection is not necessarily in the interior of the entire Geometry, since another edge may have an endpoint equal to the intersection, which according to SFS semantics can result in the point being on the Boundary of the Geometry.


hasProperInteriorIntersection

public boolean hasProperInteriorIntersection()
A proper interior intersection is a proper intersection which is not contained in the set of boundary nodes set for this SegmentIntersector.


hasInteriorIntersection

public boolean hasInteriorIntersection()
An interior intersection is an intersection which is in the interior of some segment.


processIntersections

public void processIntersections(SegmentString e0,
                                 int segIndex0,
                                 SegmentString e1,
                                 int segIndex1)
This method is called by clients of the SegmentIntersector class to process intersections for two segments of the SegmentStrings being intersected. Note that some clients (such as MonotoneChains) may optimize away this call for segment pairs which they have determined do not intersect (e.g. by an disjoint envelope test).

Specified by:
<A HREF="../../../../com/vividsolutions/jts/noding/SegmentIntersector.html#processIntersections(com.vividsolutions.jts.noding.SegmentString, int, com.vividsolutions.jts.noding.SegmentString, int)">processIntersections in interface SegmentIntersector

isDone

public boolean isDone()
Always process all intersections

Specified by:
isDone in interface SegmentIntersector
Returns:
false always



IntersectionFinderAdder <SCRIPT type="text/javascript"> function windowTitle() { parent.document.title="IntersectionFinderAdder"; } </SCRIPT>

com.vividsolutions.jts.noding
Class IntersectionFinderAdder

java.lang.Object
  extended bycom.vividsolutions.jts.noding.IntersectionFinderAdder
All Implemented Interfaces:
SegmentIntersector

public class IntersectionFinderAdder
extends java.lang.Object
implements SegmentIntersector

Finds proper and interior intersections in a set of SegmentStrings, and adds them as nodes.

Version:
1.7

Constructor Summary
IntersectionFinderAdder(LineIntersector li)
          Creates an intersection finder which finds all proper intersections
 
Method Summary
 java.util.List getInteriorIntersections()
           
 boolean isDone()
          Always process all intersections
 void <A HREF="../../../../com/vividsolutions/jts/noding/IntersectionFinderAdder.html#processIntersections(com.vividsolutions.jts.noding.SegmentString, int, com.vividsolutions.jts.noding.SegmentString, int)">processIntersections(SegmentString e0, int segIndex0, SegmentString e1, int segIndex1)
          This method is called by clients of the SegmentIntersector class to process intersections for two segments of the SegmentStrings being intersected.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

IntersectionFinderAdder

public IntersectionFinderAdder(LineIntersector li)
Creates an intersection finder which finds all proper intersections

Parameters:
li - the LineIntersector to use
Method Detail

getInteriorIntersections

public java.util.List getInteriorIntersections()

processIntersections

public void processIntersections(SegmentString e0,
                                 int segIndex0,
                                 SegmentString e1,
                                 int segIndex1)
This method is called by clients of the SegmentIntersector class to process intersections for two segments of the SegmentStrings being intersected. Note that some clients (such as MonotoneChains) may optimize away this call for segment pairs which they have determined do not intersect (e.g. by an disjoint envelope test).

Specified by:
<A HREF="../../../../com/vividsolutions/jts/noding/SegmentIntersector.html#processIntersections(com.vividsolutions.jts.noding.SegmentString, int, com.vividsolutions.jts.noding.SegmentString, int)">processIntersections in interface SegmentIntersector

isDone

public boolean isDone()
Always process all intersections

Specified by:
isDone in interface SegmentIntersector
Returns:
false always



LineIntersectionAdder <SCRIPT type="text/javascript"> function windowTitle() { parent.document.title="LineIntersectionAdder"; } </SCRIPT>

com.vividsolutions.jts.geom.prep
Class LineIntersectionAdder

java.lang.Object
  extended bycom.vividsolutions.jts.geom.prep.LineIntersectionAdder
All Implemented Interfaces:
SegmentIntersector

public class LineIntersectionAdder
extends java.lang.Object
implements SegmentIntersector

Computes the intersections between two line segments in SegmentStrings and adds them to each string. The SegmentIntersector is passed to a Noder. The addIntersections method is called whenever the Noder detects that two SegmentStrings might intersect. This class is an example of the Strategy pattern.

Version:
1.7

Field Summary
 int numInteriorIntersections
           
 int numIntersections
           
 int numProperIntersections
           
 int numTests
           
 
Constructor Summary
LineIntersectionAdder(LineIntersector li)
           
 
Method Summary
 LineIntersector getLineIntersector()
           
 Coordinate getProperIntersectionPoint()
           
 boolean hasInteriorIntersection()
          An interior intersection is an intersection which is in the interior of some segment.
 boolean hasIntersection()
           
 boolean hasProperInteriorIntersection()
          A proper interior intersection is a proper intersection which is not contained in the set of boundary nodes set for this SegmentIntersector.
 boolean hasProperIntersection()
          A proper intersection is an intersection which is interior to at least two line segments.
static boolean <A HREF="../../../../../com/vividsolutions/jts/geom/prep/LineIntersectionAdder.html#isAdjacentSegments(int, int)">isAdjacentSegments(int i1, int i2)
           
 boolean isDone()
          Always process all intersections
 void <A HREF="../../../../../com/vividsolutions/jts/geom/prep/LineIntersectionAdder.html#processIntersections(com.vividsolutions.jts.noding.SegmentString, int, com.vividsolutions.jts.noding.SegmentString, int)">processIntersections(SegmentString e0, int segIndex0, SegmentString e1, int segIndex1)
          This method is called by clients of the SegmentIntersector class to process intersections for two segments of the SegmentStrings being intersected.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

numIntersections

public int numIntersections

numInteriorIntersections

public int numInteriorIntersections

numProperIntersections

public int numProperIntersections

numTests

public int numTests
Constructor Detail

LineIntersectionAdder

public LineIntersectionAdder(LineIntersector li)
Method Detail

isAdjacentSegments

public static boolean isAdjacentSegments(int i1,
                                         int i2)

getLineIntersector

public LineIntersector getLineIntersector()

getProperIntersectionPoint

public Coordinate getProperIntersectionPoint()
Returns:
the proper intersection point, or null if none was found

hasIntersection

public boolean hasIntersection()

hasProperIntersection

public boolean hasProperIntersection()
A proper intersection is an intersection which is interior to at least two line segments. Note that a proper intersection is not necessarily in the interior of the entire Geometry, since another edge may have an endpoint equal to the intersection, which according to SFS semantics can result in the point being on the Boundary of the Geometry.


hasProperInteriorIntersection

public boolean hasProperInteriorIntersection()
A proper interior intersection is a proper intersection which is not contained in the set of boundary nodes set for this SegmentIntersector.


hasInteriorIntersection

public boolean hasInteriorIntersection()
An interior intersection is an intersection which is in the interior of some segment.


processIntersections

public void processIntersections(SegmentString e0,
                                 int segIndex0,
                                 SegmentString e1,
                                 int segIndex1)
This method is called by clients of the SegmentIntersector class to process intersections for two segments of the SegmentStrings being intersected. Note that some clients (such as MonotoneChains) may optimize away this call for segment pairs which they have determined do not intersect (e.g. by an disjoint envelope test).

Specified by:
<A HREF="../../../../../com/vividsolutions/jts/noding/SegmentIntersector.html#processIntersections(com.vividsolutions.jts.noding.SegmentString, int, com.vividsolutions.jts.noding.SegmentString, int)">processIntersections in interface SegmentIntersector

isDone

public boolean isDone()
Always process all intersections

Specified by:
isDone in interface SegmentIntersector
Returns:
false always



SegmentIntersectionDetector <SCRIPT type="text/javascript"> function windowTitle() { parent.document.title="SegmentIntersectionDetector"; } </SCRIPT>

com.vividsolutions.jts.noding
Class SegmentIntersectionDetector

java.lang.Object
  extended bycom.vividsolutions.jts.noding.SegmentIntersectionDetector
All Implemented Interfaces:
SegmentIntersector

public class SegmentIntersectionDetector
extends java.lang.Object
implements SegmentIntersector

Detects and records an intersection between two SegmentStrings, if one exists. Only a single intersection is recorded. This strategy can be configured to search for proper intersections. In this case, the presence of any intersection will still be recorded, but searching will continue until either a proper intersection has been found or no intersections are detected.

Version:
1.7

Constructor Summary
SegmentIntersectionDetector(LineIntersector li)
          Creates an intersection finder
 
Method Summary
 Coordinate getIntersection()
          Gets the computed location of the intersection.
 Coordinate[] getIntersectionSegments()
          Gets the endpoints of the intersecting segments.
 boolean hasIntersection()
          Tests whether an intersection was found.
 boolean hasNonProperIntersection()
          Tests whether a non-proper intersection was found.
 boolean hasProperIntersection()
          Tests whether a proper intersection was found.
 boolean isDone()
          Reports whether the client of this class needs to continue testing all intersections in an arrangement.
 void <A HREF="../../../../com/vividsolutions/jts/noding/SegmentIntersectionDetector.html#processIntersections(com.vividsolutions.jts.noding.SegmentString, int, com.vividsolutions.jts.noding.SegmentString, int)">processIntersections(SegmentString e0, int segIndex0, SegmentString e1, int segIndex1)
          This method is called by clients of the SegmentIntersector class to process intersections for two segments of the SegmentStrings being intersected.
 void setFindAllIntersectionTypes(boolean findAllTypes)
           
 void setFindProper(boolean findProper)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

SegmentIntersectionDetector

public SegmentIntersectionDetector(LineIntersector li)
Creates an intersection finder

Parameters:
li - the LineIntersector to use
Method Detail

setFindProper

public void setFindProper(boolean findProper)

setFindAllIntersectionTypes

public void setFindAllIntersectionTypes(boolean findAllTypes)

hasIntersection

public boolean hasIntersection()
Tests whether an intersection was found.

Returns:
true if an intersection was found

hasProperIntersection

public boolean hasProperIntersection()
Tests whether a proper intersection was found.

Returns:
true if a proper intersection was found

hasNonProperIntersection

public boolean hasNonProperIntersection()
Tests whether a non-proper intersection was found.

Returns:
true if a non-proper intersection was found

getIntersection

public Coordinate getIntersection()
Gets the computed location of the intersection. Due to round-off, the location may not be exact.

Returns:
the coordinate for the intersection location

getIntersectionSegments

public Coordinate[] getIntersectionSegments()
Gets the endpoints of the intersecting segments.

Returns:
an array of the segment endpoints (p00, p01, p10, p11)

processIntersections

public void processIntersections(SegmentString e0,
                                 int segIndex0,
                                 SegmentString e1,
                                 int segIndex1)
This method is called by clients of the SegmentIntersector class to process intersections for two segments of the SegmentStrings being intersected. Note that some clients (such as MonotoneChains) may optimize away this call for segment pairs which they have determined do not intersect (e.g. by an disjoint envelope test).

Specified by:
<A HREF="../../../../com/vividsolutions/jts/noding/SegmentIntersector.html#processIntersections(com.vividsolutions.jts.noding.SegmentString, int, com.vividsolutions.jts.noding.SegmentString, int)">processIntersections in interface SegmentIntersector

isDone

public boolean isDone()
Description copied from interface: SegmentIntersector
Reports whether the client of this class needs to continue testing all intersections in an arrangement.

Specified by:
isDone in interface SegmentIntersector
Returns:
true if there is no need to continue testing segments



_______________________________________________
jts-devel mailing list
[hidden email]
http://lists.refractions.net/mailman/listinfo/jts-devel

eider.vcf (472 bytes) Download Attachment
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Splitting a polygon

michaelm-2
Hi,

Here is a simple script solving the first part (noding) of your problem
(take care, beanshell syntax is used)

import com.vividsolutions.jts.noding.*;
import com.vividsolutions.jts.algorithm.RobustLineIntersector;

gf = new GeometryFactory();

// get the selected features (linestrings and polygons without hole only
ff = wc.layerViewPanel.selectionManager.featuresWithSelectedItems;

// add the linestrings to a list of NodedSegmentString
list = new ArrayList();
for (f : ff) {
  list.add(new NodedSegmentString(f.geometry.coordinates, null));
}

// create a noder and computes the nodes
noder = new MCIndexNoder();
noder.setSegmentIntersector(new IntersectionAdder(new
RobustLineIntersector()));
noder.computeNodes(list);

// get noded substrings and create LINESTRING geometries from them
list = noder.nodedSubstrings;
for (substring : list) print(gf.createLineString(substring.coordinates));

// you still have to polygonize your noded linestrings

Hope that helps

Michaël

Dipl. Inf. Carsten Eider a écrit :

> Hi list,
>
> i am getting sick while trying to resolve my problem of splitting a
> polygon(assumd to have no wholes within),
> it is driving me crazy! martin gave the hint:
>
> "Use MCIndexNoder to node the polygon and linestring together,
> Polygonizer to polygonize the noded edges, and then PointLocater to
> determine which of the resultant  polygons correspond to the input
> polygon. "
>
> Here is my non working attempt
>
> Polygon p, LineString l;
>
> //Use MCIndexNoder
> //Setup intersector any classes implementing SegmentIntersector
> (InteriorIntersectionFinder
> <mailbox:///G%7C/Documents%20and%20Settings/Travail/Application%20Data/Thunderbird/Profiles/nwn2wsnb.default/Mail/Local%20Folders/Inbox?number=171338383&header=quotebody&part=1.1.1.2&filename=InteriorIntersectionFinder.html>,
> IntersectionAdder
> <mailbox:///G%7C/Documents%20and%20Settings/Travail/Application%20Data/Thunderbird/Profiles/nwn2wsnb.default/Mail/Local%20Folders/Inbox?number=171338383&header=quotebody&part=1.1.1.3&filename=IntersectionAdder.html>,
> IntersectionFinderAdder
> <mailbox:///G%7C/Documents%20and%20Settings/Travail/Application%20Data/Thunderbird/Profiles/nwn2wsnb.default/Mail/Local%20Folders/Inbox?number=171338383&header=quotebody&part=1.1.1.4&filename=IntersectionFinderAdder.html>,
> LineIntersectionAdder
> <mailbox:///G%7C/Documents%20and%20Settings/Travail/Application%20Data/Thunderbird/Profiles/nwn2wsnb.default/Mail/Local%20Folders/Inbox?number=171338383&header=quotebody&part=1.1.1.5&filename=LineIntersectionAdder.html>,
> SegmentIntersectionDetector
> <mailbox:///G%7C/Documents%20and%20Settings/Travail/Application%20Data/Thunderbird/Profiles/nwn2wsnb.default/Mail/Local%20Folders/Inbox?number=171338383&header=quotebody&part=1.1.1.6&filename=SegmentIntersectionDetector.html>)
> have been tested!
> SegmentIntersectionDetector _intersector = new
> SegmentIntersectionDetector(new RobustLineIntersector());
> _intersector.setFindProper(true);
> _intersector.setFindAllIntersectionTypes(true);
>
> //Wouldn't it be better to setup intersector within the constructor?
> MCIndexNoder _mci = new MCIndexNoder();
> _mci.setSegmentIntersector(_intersector);
> // Add my polygon and my LineString
> NodedSegmentString _pseg = new NodedSegmentString(p.getCoordinates(),
> null);
> NodedSegmentString _lseg = new NodedSegmentString(l.getCoordinates(),
> null);
> Vector<NodedSegmentString> _v = new Vector<NodedSegmentString>();
> //order of adding doesn't alter result
> _v.add(_pseg);
> _v.add(_lseg);
> //lets compute the nodes, whatever this does mean!
> _mci.computeNodes(_v);
> //here is my polygonizer
> Polygonizer _polygonizer = new Polygonizer();
> //let's add thsi monotonechains, whatever they mean!
> for (Object o : _mci.getMonotoneChains()) {
>             MonotoneChain _mtc = (MonotoneChain) o;
>              //Convert chain to a linestring, is thsi correct?
>             LineString _line =
> _fac.createLineString(_mtc.getCoordinates());
>             System.out.println(_line);
>             _polygonizer.add(_line);
> }
> //Here are my hopefully correct poylgons!
> Collection<Polygon> _polygons = _polygonizer.getPolygons();
> for (Polygon _p : _polygons) {
>            /System.out.println(_p);
> }
>
> Example 1:
> l=LINESTRING (0 0,4 5, 5 4,10 10);
> p=POLYGON(0 0,10 0,10 10 ,0 10, 3 8,0 0)
> pgsql:<polygon>POLYGON ((10 10, 10 0, 0 0, 4 5, 5 4, 10
> 10))</polygon><polygon>POLYGON ((0 0, 3 8, 0 10, 10 10, 5 4, 4 5, 0
> 0))</polygon>
> jts:<polygon>POLYGON ((5 4, 4 5, 0 0, 3 8, 0 10, 10 10, 5
> 4))</polygon><polygon>POLYGON ((0 0, 4 5, 5 4, 10 10, 10 0, 0
> 0))</polygon>
>
> jts==pgsql==>Correct GREAT
>
> Example 2:
> l=LINESTRING (-1 -1,4 5, 5 4,11 11);
> p=POLYGON(0 0,10 0,10 10 ,0 10, 3 8,0 0)
> pgsql:<polygon>POLYGON ((10 9.83333333333333, 10 0, 0 0,
> 0.136363636363636 0.363636363636364, 4 5, 5 4, 10
> 9.83333333333333))</polygon><polygon>POLYGON ((0.136363636363636
> 0.363636363636364, 3 8, 0 10, 10 10, 10 9.83333333333333, 5 4, 4 5,
> 0.136363636363636 0.363636363636364))</polygon>
> jts:<polygon>POLYGON ((0 0, 3 8, 0 10, 10 10, 10 0, 0 0))</polygon>
>
> jts!=pgsql, damn where is my second polygon as expected? why do i get
> just my original polygon?
>
>
> Example 3
> l=LINESTRING (0 0,4 5, 5 4,10 10,10 6,0 6)
> p=POLYGON(0 0,10 0,10 10 ,0 10, 3 8,0 0)
> pgsql:<polygon>POLYGON ((10 6, 10 0, 0 0, 4 5, 5 4, 6.66666666666667
> 6, 10 6))</polygon><polygon>POLYGON ((10 10, 10 6, 6.66666666666667 6,
> 10 10))</polygon><polygon>POLYGON ((2.25 6, 3 8, 0 10, 10 10,
> 6.66666666666667 6, 2.25 6))</polygon><polygon>POLYGON ((0 0, 2.25 6,
> 6.66666666666667 6, 5 4, 4 5, 0 0))</polygon>
> jts:<polygon>POLYGON ((5 4, 4 5, 0 0, 3 8, 0 10, 10 10, 5
> 4))</polygon><polygon>POLYGON ((0 0, 4 5, 5 4, 10 10, 10 0, 0
> 0))</polygon>
>
> jts!=pgsql, why the hell are there only two polygons left? where are
> the other two as expected?
>
>
> Any suggestions are very appreciated!
> Maybe i should offer a reward of a box of good german beer !
>
> TIA Carsten
> --
> Mit freundlichen Grüßen / Yours faithfully
> Carsten Eider
>
> Dipl. Inf. (FH)
>
> Kompetenzzentrum für Innovative Informationssysteme
>
> c/o Fachhochschhule Bingen / University of applied sciences Bingen
>
> Berlinstraße 109
> 55411 Bingen
>
> Tel: +49 (0) 6721 / 409-179
> Fax: +49 (0) 6721 / 409-158
> email: [hidden email] <mailto:[hidden email]>
> Internet: iis.fh-bingen.de
> _______________________________________________
> jts-devel mailing list
> [hidden email]
> http://lists.refractions.net/mailman/listinfo/jts-devel
>  

_______________________________________________
jts-devel mailing list
[hidden email]
http://lists.refractions.net/mailman/listinfo/jts-devel
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Splitting a polygon

michaelm-2
Sorry, I used some jump code,

pure jts could be :

import com.vividsolutions.jts.noding.*;
import com.vividsolutions.jts.algorithm.RobustLineIntersector;

gf = new GeometryFactory();

// add the linestrings to a list of NodedSegmentString;
List list = new ArrayList();
list.add(new NodedSegmentString(geometry1.getCoordinates(), null));
list.add(new NodedSegmentString(geometry2.getCoordinates(), null));

// create a noder and computes the nodes
Noder noder = new MCIndexNoder();
noder.setSegmentIntersector(new IntersectionAdder(new
RobustLineIntersector()));
noder.computeNodes(list);

// get noded substrings and create LINESTRING geometries from them

list = noder.getNodedSubstrings();
for (Object substring : list)
print(gf.createLineString(((NodedSegmentString)substring).getCoordinates()));
 
// you still have to polygonize your noded linestrings

> Hope that helps
>
> Michaël
>
> Dipl. Inf. Carsten Eider a écrit :
>> Hi list,
>>
>> i am getting sick while trying to resolve my problem of splitting a
>> polygon(assumd to have no wholes within),
>> it is driving me crazy! martin gave the hint:
>>
>> "Use MCIndexNoder to node the polygon and linestring together,
>> Polygonizer to polygonize the noded edges, and then PointLocater to
>> determine which of the resultant  polygons correspond to the input
>> polygon. "
>>
>> Here is my non working attempt
>>
>> Polygon p, LineString l;
>>
>> //Use MCIndexNoder
>> //Setup intersector any classes implementing SegmentIntersector
>> (InteriorIntersectionFinder
>> <mailbox:///G%7C/Documents%20and%20Settings/Travail/Application%20Data/Thunderbird/Profiles/nwn2wsnb.default/Mail/Local%20Folders/Inbox?number=171338383&header=quotebody&part=1.1.1.2&filename=InteriorIntersectionFinder.html>,
>> IntersectionAdder
>> <mailbox:///G%7C/Documents%20and%20Settings/Travail/Application%20Data/Thunderbird/Profiles/nwn2wsnb.default/Mail/Local%20Folders/Inbox?number=171338383&header=quotebody&part=1.1.1.3&filename=IntersectionAdder.html>,
>> IntersectionFinderAdder
>> <mailbox:///G%7C/Documents%20and%20Settings/Travail/Application%20Data/Thunderbird/Profiles/nwn2wsnb.default/Mail/Local%20Folders/Inbox?number=171338383&header=quotebody&part=1.1.1.4&filename=IntersectionFinderAdder.html>,
>> LineIntersectionAdder
>> <mailbox:///G%7C/Documents%20and%20Settings/Travail/Application%20Data/Thunderbird/Profiles/nwn2wsnb.default/Mail/Local%20Folders/Inbox?number=171338383&header=quotebody&part=1.1.1.5&filename=LineIntersectionAdder.html>,
>> SegmentIntersectionDetector
>> <mailbox:///G%7C/Documents%20and%20Settings/Travail/Application%20Data/Thunderbird/Profiles/nwn2wsnb.default/Mail/Local%20Folders/Inbox?number=171338383&header=quotebody&part=1.1.1.6&filename=SegmentIntersectionDetector.html>)
>> have been tested!
>> SegmentIntersectionDetector _intersector = new
>> SegmentIntersectionDetector(new RobustLineIntersector());
>> _intersector.setFindProper(true);
>> _intersector.setFindAllIntersectionTypes(true);
>>
>> //Wouldn't it be better to setup intersector within the constructor?
>> MCIndexNoder _mci = new MCIndexNoder();
>> _mci.setSegmentIntersector(_intersector);
>> // Add my polygon and my LineString
>> NodedSegmentString _pseg = new NodedSegmentString(p.getCoordinates(),
>> null);
>> NodedSegmentString _lseg = new NodedSegmentString(l.getCoordinates(),
>> null);
>> Vector<NodedSegmentString> _v = new Vector<NodedSegmentString>();
>> //order of adding doesn't alter result
>> _v.add(_pseg);
>> _v.add(_lseg);
>> //lets compute the nodes, whatever this does mean!
>> _mci.computeNodes(_v);
>> //here is my polygonizer
>> Polygonizer _polygonizer = new Polygonizer();
>> //let's add thsi monotonechains, whatever they mean!
>> for (Object o : _mci.getMonotoneChains()) {
>>             MonotoneChain _mtc = (MonotoneChain) o;
>>              //Convert chain to a linestring, is thsi correct?
>>             LineString _line =
>> _fac.createLineString(_mtc.getCoordinates());
>>             System.out.println(_line);
>>             _polygonizer.add(_line);
>> }
>> //Here are my hopefully correct poylgons!
>> Collection<Polygon> _polygons = _polygonizer.getPolygons();
>> for (Polygon _p : _polygons) {
>>            /System.out.println(_p);
>> }
>>
>> Example 1:
>> l=LINESTRING (0 0,4 5, 5 4,10 10);
>> p=POLYGON(0 0,10 0,10 10 ,0 10, 3 8,0 0)
>> pgsql:<polygon>POLYGON ((10 10, 10 0, 0 0, 4 5, 5 4, 10
>> 10))</polygon><polygon>POLYGON ((0 0, 3 8, 0 10, 10 10, 5 4, 4 5, 0
>> 0))</polygon>
>> jts:<polygon>POLYGON ((5 4, 4 5, 0 0, 3 8, 0 10, 10 10, 5
>> 4))</polygon><polygon>POLYGON ((0 0, 4 5, 5 4, 10 10, 10 0, 0
>> 0))</polygon>
>>
>> jts==pgsql==>Correct GREAT
>>
>> Example 2:
>> l=LINESTRING (-1 -1,4 5, 5 4,11 11);
>> p=POLYGON(0 0,10 0,10 10 ,0 10, 3 8,0 0)
>> pgsql:<polygon>POLYGON ((10 9.83333333333333, 10 0, 0 0,
>> 0.136363636363636 0.363636363636364, 4 5, 5 4, 10
>> 9.83333333333333))</polygon><polygon>POLYGON ((0.136363636363636
>> 0.363636363636364, 3 8, 0 10, 10 10, 10 9.83333333333333, 5 4, 4 5,
>> 0.136363636363636 0.363636363636364))</polygon>
>> jts:<polygon>POLYGON ((0 0, 3 8, 0 10, 10 10, 10 0, 0 0))</polygon>
>>
>> jts!=pgsql, damn where is my second polygon as expected? why do i get
>> just my original polygon?
>>
>>
>> Example 3
>> l=LINESTRING (0 0,4 5, 5 4,10 10,10 6,0 6)
>> p=POLYGON(0 0,10 0,10 10 ,0 10, 3 8,0 0)
>> pgsql:<polygon>POLYGON ((10 6, 10 0, 0 0, 4 5, 5 4, 6.66666666666667
>> 6, 10 6))</polygon><polygon>POLYGON ((10 10, 10 6, 6.66666666666667
>> 6, 10 10))</polygon><polygon>POLYGON ((2.25 6, 3 8, 0 10, 10 10,
>> 6.66666666666667 6, 2.25 6))</polygon><polygon>POLYGON ((0 0, 2.25 6,
>> 6.66666666666667 6, 5 4, 4 5, 0 0))</polygon>
>> jts:<polygon>POLYGON ((5 4, 4 5, 0 0, 3 8, 0 10, 10 10, 5
>> 4))</polygon><polygon>POLYGON ((0 0, 4 5, 5 4, 10 10, 10 0, 0
>> 0))</polygon>
>>
>> jts!=pgsql, why the hell are there only two polygons left? where are
>> the other two as expected?
>>
>>
>> Any suggestions are very appreciated!
>> Maybe i should offer a reward of a box of good german beer !
>>
>> TIA Carsten
>> --
>> Mit freundlichen Grüßen / Yours faithfully
>> Carsten Eider
>>
>> Dipl. Inf. (FH)
>>
>> Kompetenzzentrum für Innovative Informationssysteme
>>
>> c/o Fachhochschhule Bingen / University of applied sciences Bingen
>>
>> Berlinstraße 109
>> 55411 Bingen
>>
>> Tel: +49 (0) 6721 / 409-179
>> Fax: +49 (0) 6721 / 409-158
>> email: [hidden email] <mailto:[hidden email]>
>> Internet: iis.fh-bingen.de
>> _______________________________________________
>> jts-devel mailing list
>> [hidden email]
>> http://lists.refractions.net/mailman/listinfo/jts-devel
>>  
>
> _______________________________________________
> jts-devel mailing list
> [hidden email]
> http://lists.refractions.net/mailman/listinfo/jts-devel
>
>

_______________________________________________
jts-devel mailing list
[hidden email]
http://lists.refractions.net/mailman/listinfo/jts-devel
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Splitting a polygon

Dipl. Inf. Carsten Eider
Hi Michaël

thank you for your hint, this is equal to my solution.

> // you still have to polygonize your noded linestrings
Polygonizer _polygonizer = new Polygonizer();

list = noder.getNodedSubstrings();
for (Object substring : list)
_polygonizer.add(gf.createLineString(((NodedSegmentString)substring).getCoordinates()));


Collection<Polygon> _polygons = _polygonizer.getPolygons();
for (Polygon _p : _polygons) {
           System.out.println(_p);
}

This doesn't work at all.
Sometimes the amout of polyons is correct, but the polygons themselfes not.

>
>> Hope that helps
>>
>> Michaël
>>
>> Dipl. Inf. Carsten Eider a écrit :
>>> Hi list,
>>>
>>> i am getting sick while trying to resolve my problem of splitting a
>>> polygon(assumd to have no wholes within),
>>> it is driving me crazy! martin gave the hint:
>>>
>>> "Use MCIndexNoder to node the polygon and linestring together,
>>> Polygonizer to polygonize the noded edges, and then PointLocater to
>>> determine which of the resultant  polygons correspond to the input
>>> polygon. "
>>>
>>> Here is my non working attempt
>>>
>>> Polygon p, LineString l;
>>>
>>> //Use MCIndexNoder
>>> //Setup intersector any classes implementing SegmentIntersector
>>> (InteriorIntersectionFinder
>>> <mailbox:///G%7C/Documents%20and%20Settings/Travail/Application%20Data/Thunderbird/Profiles/nwn2wsnb.default/Mail/Local%20Folders/Inbox?number=171338383&header=quotebody&part=1.1.1.2&filename=InteriorIntersectionFinder.html>,
>>> IntersectionAdder
>>> <mailbox:///G%7C/Documents%20and%20Settings/Travail/Application%20Data/Thunderbird/Profiles/nwn2wsnb.default/Mail/Local%20Folders/Inbox?number=171338383&header=quotebody&part=1.1.1.3&filename=IntersectionAdder.html>,
>>> IntersectionFinderAdder
>>> <mailbox:///G%7C/Documents%20and%20Settings/Travail/Application%20Data/Thunderbird/Profiles/nwn2wsnb.default/Mail/Local%20Folders/Inbox?number=171338383&header=quotebody&part=1.1.1.4&filename=IntersectionFinderAdder.html>,
>>> LineIntersectionAdder
>>> <mailbox:///G%7C/Documents%20and%20Settings/Travail/Application%20Data/Thunderbird/Profiles/nwn2wsnb.default/Mail/Local%20Folders/Inbox?number=171338383&header=quotebody&part=1.1.1.5&filename=LineIntersectionAdder.html>,
>>> SegmentIntersectionDetector
>>> <mailbox:///G%7C/Documents%20and%20Settings/Travail/Application%20Data/Thunderbird/Profiles/nwn2wsnb.default/Mail/Local%20Folders/Inbox?number=171338383&header=quotebody&part=1.1.1.6&filename=SegmentIntersectionDetector.html>)
>>> have been tested!
>>> SegmentIntersectionDetector _intersector = new
>>> SegmentIntersectionDetector(new RobustLineIntersector());
>>> _intersector.setFindProper(true);
>>> _intersector.setFindAllIntersectionTypes(true);
>>>
>>> //Wouldn't it be better to setup intersector within the constructor?
>>> MCIndexNoder _mci = new MCIndexNoder();
>>> _mci.setSegmentIntersector(_intersector);
>>> // Add my polygon and my LineString
>>> NodedSegmentString _pseg = new
>>> NodedSegmentString(p.getCoordinates(), null);
>>> NodedSegmentString _lseg = new
>>> NodedSegmentString(l.getCoordinates(), null);
>>> Vector<NodedSegmentString> _v = new Vector<NodedSegmentString>();
>>> //order of adding doesn't alter result
>>> _v.add(_pseg);
>>> _v.add(_lseg);
>>> //lets compute the nodes, whatever this does mean!
>>> _mci.computeNodes(_v);
>>> //here is my polygonizer
>>> Polygonizer _polygonizer = new Polygonizer();
>>> //let's add thsi monotonechains, whatever they mean!
>>> for (Object o : _mci.getMonotoneChains()) {
>>>             MonotoneChain _mtc = (MonotoneChain) o;
>>>              //Convert chain to a linestring, is thsi correct?
>>>             LineString _line =
>>> _fac.createLineString(_mtc.getCoordinates());
>>>             System.out.println(_line);
>>>             _polygonizer.add(_line);
>>> }
>>> //Here are my hopefully correct poylgons!
>>> Collection<Polygon> _polygons = _polygonizer.getPolygons();
>>> for (Polygon _p : _polygons) {
>>>            /System.out.println(_p);
>>> }
>>>
>>> Example 1:
>>> l=LINESTRING (0 0,4 5, 5 4,10 10);
>>> p=POLYGON(0 0,10 0,10 10 ,0 10, 3 8,0 0)
>>> pgsql:<polygon>POLYGON ((10 10, 10 0, 0 0, 4 5, 5 4, 10
>>> 10))</polygon><polygon>POLYGON ((0 0, 3 8, 0 10, 10 10, 5 4, 4 5, 0
>>> 0))</polygon>
>>> jts:<polygon>POLYGON ((5 4, 4 5, 0 0, 3 8, 0 10, 10 10, 5
>>> 4))</polygon><polygon>POLYGON ((0 0, 4 5, 5 4, 10 10, 10 0, 0
>>> 0))</polygon>
>>>
>>> jts==pgsql==>Correct GREAT
>>>
>>> Example 2:
>>> l=LINESTRING (-1 -1,4 5, 5 4,11 11);
>>> p=POLYGON(0 0,10 0,10 10 ,0 10, 3 8,0 0)
>>> pgsql:<polygon>POLYGON ((10 9.83333333333333, 10 0, 0 0,
>>> 0.136363636363636 0.363636363636364, 4 5, 5 4, 10
>>> 9.83333333333333))</polygon><polygon>POLYGON ((0.136363636363636
>>> 0.363636363636364, 3 8, 0 10, 10 10, 10 9.83333333333333, 5 4, 4 5,
>>> 0.136363636363636 0.363636363636364))</polygon>
>>> jts:<polygon>POLYGON ((0 0, 3 8, 0 10, 10 10, 10 0, 0 0))</polygon>
>>>
>>> jts!=pgsql, damn where is my second polygon as expected? why do i
>>> get just my original polygon?
>>>
>>>
>>> Example 3
>>> l=LINESTRING (0 0,4 5, 5 4,10 10,10 6,0 6)
>>> p=POLYGON(0 0,10 0,10 10 ,0 10, 3 8,0 0)
>>> pgsql:<polygon>POLYGON ((10 6, 10 0, 0 0, 4 5, 5 4, 6.66666666666667
>>> 6, 10 6))</polygon><polygon>POLYGON ((10 10, 10 6, 6.66666666666667
>>> 6, 10 10))</polygon><polygon>POLYGON ((2.25 6, 3 8, 0 10, 10 10,
>>> 6.66666666666667 6, 2.25 6))</polygon><polygon>POLYGON ((0 0, 2.25
>>> 6, 6.66666666666667 6, 5 4, 4 5, 0 0))</polygon>
>>> jts:<polygon>POLYGON ((5 4, 4 5, 0 0, 3 8, 0 10, 10 10, 5
>>> 4))</polygon><polygon>POLYGON ((0 0, 4 5, 5 4, 10 10, 10 0, 0
>>> 0))</polygon>
>>>
>>> jts!=pgsql, why the hell are there only two polygons left? where are
>>> the other two as expected?
>>>
>>>
>>> Any suggestions are very appreciated!
>>> Maybe i should offer a reward of a box of good german beer !
>>>
>>> TIA Carsten
>>> --
>>> Mit freundlichen Grüßen / Yours faithfully
>>> Carsten Eider
>>>
>>> Dipl. Inf. (FH)
>>>
>>> Kompetenzzentrum für Innovative Informationssysteme
>>>
>>> c/o Fachhochschhule Bingen / University of applied sciences Bingen
>>>
>>> Berlinstraße 109
>>> 55411 Bingen
>>>
>>> Tel: +49 (0) 6721 / 409-179
>>> Fax: +49 (0) 6721 / 409-158
>>> email: [hidden email] <mailto:[hidden email]>
>>> Internet: iis.fh-bingen.de
>>> _______________________________________________
>>> jts-devel mailing list
>>> [hidden email]
>>> http://lists.refractions.net/mailman/listinfo/jts-devel
>>>  
>>
>> _______________________________________________
>> jts-devel mailing list
>> [hidden email]
>> http://lists.refractions.net/mailman/listinfo/jts-devel
>>
>>
>
> _______________________________________________
> jts-devel mailing list
> [hidden email]
> http://lists.refractions.net/mailman/listinfo/jts-devel
>
--
Mit freundlichen Grüßen / Yours faithfully
Carsten Eider

Dipl. Inf. (FH)

Kompetenzzentrum für Innovative Informationssysteme

c/o Fachhochschhule Bingen / University of applied sciences Bingen

Berlinstraße 109
55411 Bingen

Tel: +49 (0) 6721 / 409-179
Fax: +49 (0) 6721 / 409-158
email: [hidden email]
Internet: iis.fh-bingen.de


_______________________________________________
jts-devel mailing list
[hidden email]
http://lists.refractions.net/mailman/listinfo/jts-devel

eider.vcf (472 bytes) Download Attachment
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

[Solution] Splitting a polygon

Dipl. Inf. Carsten Eider
In reply to this post by michaelm-2
Hi folks,

here is my working solution,adapted to my requirements:

    private String jtsSplit(Polygon p, LineString l) {
        /*
         * Use MCIndexNoder to node
        the polygon and linestring together, Polygonizer to polygonize the
        noded edges, and then PointLocater to determine which of the
resultant
        polygons correspond to the input polygon. */
        StringBuffer _buffer = new StringBuffer();
        IntersectionAdder _intersector=new IntersectionAdder(new
RobustLineIntersector());
        MCIndexNoder _mci = new MCIndexNoder();
        _mci.setSegmentIntersector(_intersector);
        NodedSegmentString _pseg = new
NodedSegmentString(p.getCoordinates(), null);
        NodedSegmentString _lseg = new
NodedSegmentString(l.getCoordinates(), null);
        Vector<NodedSegmentString> _v = new Vector<NodedSegmentString>();
        _v.add(_pseg);
        _v.add(_lseg);
        _mci.computeNodes(_v);
        GeometryFactory _fac = new GeometryFactory();
        Polygonizer _polygonizer = new Polygonizer();
        Vector<LineString> _ls = new Vector<LineString>();
        for (Object o : _mci.getMonotoneChains()) {
            MonotoneChain _mtc = (MonotoneChain) o;
            LineString _line = _fac.createLineString(_mtc.getCoordinates());
            _ls.add(_line);
        }
        Geometry nodedLineStrings =  _ls.get(0);
        for (int i = 1; i < _ls.size(); i++) {
            nodedLineStrings = nodedLineStrings.union(_ls.get(i));
        }
        _polygonizer.add(nodedLineStrings);
        Collection<Polygon> _polygons = _polygonizer.getPolygons();
        PointLocator _pl=new PointLocator();
        for (Polygon _p : _polygons) {
            if
(_pl.locate(_p.getInteriorPoint().getCoordinate(),p)==Location.INTERIOR)
            {
                _buffer.append("<polygon>");
                _buffer.append(_p);
                _buffer.append("</polygon>");
            }
        }
        return (_buffer.toString());
    }


Michael Michaud schrieb:

> Sorry, I used some jump code,
>
> pure jts could be :
>
> import com.vividsolutions.jts.noding.*;
> import com.vividsolutions.jts.algorithm.RobustLineIntersector;
>
> gf = new GeometryFactory();
>
> // add the linestrings to a list of NodedSegmentString;
> List list = new ArrayList();
> list.add(new NodedSegmentString(geometry1.getCoordinates(), null));
> list.add(new NodedSegmentString(geometry2.getCoordinates(), null));
>
> // create a noder and computes the nodes
> Noder noder = new MCIndexNoder();
> noder.setSegmentIntersector(new IntersectionAdder(new
> RobustLineIntersector()));
> noder.computeNodes(list);
>
> // get noded substrings and create LINESTRING geometries from them
>
> list = noder.getNodedSubstrings();
> for (Object substring : list)
> print(gf.createLineString(((NodedSegmentString)substring).getCoordinates()));
>
>
> // you still have to polygonize your noded linestrings
>
>> Hope that helps
>>
>> Michaël
>>
>> Dipl. Inf. Carsten Eider a écrit :
>>> Hi list,
>>>
>>> i am getting sick while trying to resolve my problem of splitting a
>>> polygon(assumd to have no wholes within),
>>> it is driving me crazy! martin gave the hint:
>>>
>>> "Use MCIndexNoder to node the polygon and linestring together,
>>> Polygonizer to polygonize the noded edges, and then PointLocater to
>>> determine which of the resultant  polygons correspond to the input
>>> polygon. "
>>>
>>> Here is my non working attempt
>>>
>>> Polygon p, LineString l;
>>>
>>> //Use MCIndexNoder
>>> //Setup intersector any classes implementing SegmentIntersector
>>> (InteriorIntersectionFinder
>>> <mailbox:///G%7C/Documents%20and%20Settings/Travail/Application%20Data/Thunderbird/Profiles/nwn2wsnb.default/Mail/Local%20Folders/Inbox?number=171338383&header=quotebody&part=1.1.1.2&filename=InteriorIntersectionFinder.html>,
>>> IntersectionAdder
>>> <mailbox:///G%7C/Documents%20and%20Settings/Travail/Application%20Data/Thunderbird/Profiles/nwn2wsnb.default/Mail/Local%20Folders/Inbox?number=171338383&header=quotebody&part=1.1.1.3&filename=IntersectionAdder.html>,
>>> IntersectionFinderAdder
>>> <mailbox:///G%7C/Documents%20and%20Settings/Travail/Application%20Data/Thunderbird/Profiles/nwn2wsnb.default/Mail/Local%20Folders/Inbox?number=171338383&header=quotebody&part=1.1.1.4&filename=IntersectionFinderAdder.html>,
>>> LineIntersectionAdder
>>> <mailbox:///G%7C/Documents%20and%20Settings/Travail/Application%20Data/Thunderbird/Profiles/nwn2wsnb.default/Mail/Local%20Folders/Inbox?number=171338383&header=quotebody&part=1.1.1.5&filename=LineIntersectionAdder.html>,
>>> SegmentIntersectionDetector
>>> <mailbox:///G%7C/Documents%20and%20Settings/Travail/Application%20Data/Thunderbird/Profiles/nwn2wsnb.default/Mail/Local%20Folders/Inbox?number=171338383&header=quotebody&part=1.1.1.6&filename=SegmentIntersectionDetector.html>)
>>> have been tested!
>>> SegmentIntersectionDetector _intersector = new
>>> SegmentIntersectionDetector(new RobustLineIntersector());
>>> _intersector.setFindProper(true);
>>> _intersector.setFindAllIntersectionTypes(true);
>>>
>>> //Wouldn't it be better to setup intersector within the constructor?
>>> MCIndexNoder _mci = new MCIndexNoder();
>>> _mci.setSegmentIntersector(_intersector);
>>> // Add my polygon and my LineString
>>> NodedSegmentString _pseg = new
>>> NodedSegmentString(p.getCoordinates(), null);
>>> NodedSegmentString _lseg = new
>>> NodedSegmentString(l.getCoordinates(), null);
>>> Vector<NodedSegmentString> _v = new Vector<NodedSegmentString>();
>>> //order of adding doesn't alter result
>>> _v.add(_pseg);
>>> _v.add(_lseg);
>>> //lets compute the nodes, whatever this does mean!
>>> _mci.computeNodes(_v);
>>> //here is my polygonizer
>>> Polygonizer _polygonizer = new Polygonizer();
>>> //let's add thsi monotonechains, whatever they mean!
>>> for (Object o : _mci.getMonotoneChains()) {
>>>             MonotoneChain _mtc = (MonotoneChain) o;
>>>              //Convert chain to a linestring, is thsi correct?
>>>             LineString _line =
>>> _fac.createLineString(_mtc.getCoordinates());
>>>             System.out.println(_line);
>>>             _polygonizer.add(_line);
>>> }
>>> //Here are my hopefully correct poylgons!
>>> Collection<Polygon> _polygons = _polygonizer.getPolygons();
>>> for (Polygon _p : _polygons) {
>>>            /System.out.println(_p);
>>> }
>>>
>>> Example 1:
>>> l=LINESTRING (0 0,4 5, 5 4,10 10);
>>> p=POLYGON(0 0,10 0,10 10 ,0 10, 3 8,0 0)
>>> pgsql:<polygon>POLYGON ((10 10, 10 0, 0 0, 4 5, 5 4, 10
>>> 10))</polygon><polygon>POLYGON ((0 0, 3 8, 0 10, 10 10, 5 4, 4 5, 0
>>> 0))</polygon>
>>> jts:<polygon>POLYGON ((5 4, 4 5, 0 0, 3 8, 0 10, 10 10, 5
>>> 4))</polygon><polygon>POLYGON ((0 0, 4 5, 5 4, 10 10, 10 0, 0
>>> 0))</polygon>
>>>
>>> jts==pgsql==>Correct GREAT
>>>
>>> Example 2:
>>> l=LINESTRING (-1 -1,4 5, 5 4,11 11);
>>> p=POLYGON(0 0,10 0,10 10 ,0 10, 3 8,0 0)
>>> pgsql:<polygon>POLYGON ((10 9.83333333333333, 10 0, 0 0,
>>> 0.136363636363636 0.363636363636364, 4 5, 5 4, 10
>>> 9.83333333333333))</polygon><polygon>POLYGON ((0.136363636363636
>>> 0.363636363636364, 3 8, 0 10, 10 10, 10 9.83333333333333, 5 4, 4 5,
>>> 0.136363636363636 0.363636363636364))</polygon>
>>> jts:<polygon>POLYGON ((0 0, 3 8, 0 10, 10 10, 10 0, 0 0))</polygon>
>>>
>>> jts!=pgsql, damn where is my second polygon as expected? why do i
>>> get just my original polygon?
>>>
>>>
>>> Example 3
>>> l=LINESTRING (0 0,4 5, 5 4,10 10,10 6,0 6)
>>> p=POLYGON(0 0,10 0,10 10 ,0 10, 3 8,0 0)
>>> pgsql:<polygon>POLYGON ((10 6, 10 0, 0 0, 4 5, 5 4, 6.66666666666667
>>> 6, 10 6))</polygon><polygon>POLYGON ((10 10, 10 6, 6.66666666666667
>>> 6, 10 10))</polygon><polygon>POLYGON ((2.25 6, 3 8, 0 10, 10 10,
>>> 6.66666666666667 6, 2.25 6))</polygon><polygon>POLYGON ((0 0, 2.25
>>> 6, 6.66666666666667 6, 5 4, 4 5, 0 0))</polygon>
>>> jts:<polygon>POLYGON ((5 4, 4 5, 0 0, 3 8, 0 10, 10 10, 5
>>> 4))</polygon><polygon>POLYGON ((0 0, 4 5, 5 4, 10 10, 10 0, 0
>>> 0))</polygon>
>>>
>>> jts!=pgsql, why the hell are there only two polygons left? where are
>>> the other two as expected?
>>>
>>>
>>> Any suggestions are very appreciated!
>>> Maybe i should offer a reward of a box of good german beer !
>>>
>>> TIA Carsten
>>> --
>>> Mit freundlichen Grüßen / Yours faithfully
>>> Carsten Eider
>>>
>>> Dipl. Inf. (FH)
>>>
>>> Kompetenzzentrum für Innovative Informationssysteme
>>>
>>> c/o Fachhochschhule Bingen / University of applied sciences Bingen
>>>
>>> Berlinstraße 109
>>> 55411 Bingen
>>>
>>> Tel: +49 (0) 6721 / 409-179
>>> Fax: +49 (0) 6721 / 409-158
>>> email: [hidden email] <mailto:[hidden email]>
>>> Internet: iis.fh-bingen.de
>>> _______________________________________________
>>> jts-devel mailing list
>>> [hidden email]
>>> http://lists.refractions.net/mailman/listinfo/jts-devel
>>>  
>>
>> _______________________________________________
>> jts-devel mailing list
>> [hidden email]
>> http://lists.refractions.net/mailman/listinfo/jts-devel
>>
>>
>
> _______________________________________________
> jts-devel mailing list
> [hidden email]
> http://lists.refractions.net/mailman/listinfo/jts-devel
>
--
Mit freundlichen Grüßen / Yours faithfully
Carsten Eider

Dipl. Inf. (FH)

Kompetenzzentrum für Innovative Informationssysteme

c/o Fachhochschhule Bingen / University of applied sciences Bingen

Berlinstraße 109
55411 Bingen

Tel: +49 (0) 6721 / 409-179
Fax: +49 (0) 6721 / 409-158
email: [hidden email]
Internet: iis.fh-bingen.de


_______________________________________________
jts-devel mailing list
[hidden email]
http://lists.refractions.net/mailman/listinfo/jts-devel

eider.vcf (472 bytes) Download Attachment
Loading...