Thank you all for the replies! <br>With a little of job I was able to distinguish and gather the parts of a IFeature.<br>However, now I have to redraw the part with different colors than the single color of the selection tools (yellow).<br>
Can someone help me with this task?<br><br>This is how I retrieve the points/linesegments composing the part of my geometry (which got 4 coordinates per point):<br><br>public static LinkedList<Part> getParts(IFeature feature) {<br>
<br> LinkedList<Part> parts = new LinkedList<Part>();<br> ArrayList<LineSegment> lineSegments = new ArrayList<LineSegment>();<br> PathIterator theIterator;<br> int theType;<br>
int numGeometries = 0;<br> IGeometry g = feature.getGeometry();<br> // Use this array to store segment coordinate data<br> double[] theData = new double[6];<br> ArrayList<Point4D> arrayCoords = new ArrayList<Point4D>();<br>
Shape internalShape = g.getInternalShape();<br> double shapeZs[] = null;<br> double shapeMs[] = null;<br> //retrieve parts only if line geometries<br> if (!(internalShape instanceof FPolyline2D) && !(internalShape instanceof FPolyline3D)<br>
&& !(internalShape instanceof FPolyline3DM))<br> return null;<br> if (internalShape instanceof FPolyline3D) {<br> shapeZs = ((FPolyline3D) internalShape).getZs();<br> if (internalShape instanceof FPolyline3DM) {<br>
shapeMs = ((FPolyline3DM) internalShape).getMs();<br> }<br> }<br> <br> theIterator = g.getPathIterator(null, FConverter.FLATNESS);<br> int pointIndex = 0;<br> while (!theIterator.isDone()) {<br>
theType = theIterator.currentSegment(theData);<br> // new part: save current one and create another lineString/curve <br> if (theType == PathIterator.SEG_MOVETO) {<br> if (lineSegments.size() > 0) {<br>
parts.add(new Part(numGeometries, lineSegments));<br> logger.debug("End of part " + numGeometries);<br> lineSegments = new ArrayList<LineSegment>();<br>
}<br> numGeometries++;<br> Point4D currentPoint = createPoint4D(theData, shapeZs, shapeMs, pointIndex);<br> arrayCoords.add(currentPoint);<br> }<br>
// segment of the current lineString/curve<br>
else if (theType == PathIterator.SEG_LINETO) {<br> Point4D currentPoint = createPoint4D(theData, shapeZs, shapeMs, pointIndex);<br> arrayCoords.add(currentPoint);<br> Point4D prevPoint = arrayCoords.get(arrayCoords.size() - 2);<br>
Coordinate pCoords = prevPoint.getAsCoordinate();<br> <br> LineSegment l = new LineSegment(pCoords, currentPoint.getAsCoordinate());<br> lineSegments.add(l);<br>
}<br> // polygon/polyline closing the geometry<br> else if (theType == PathIterator.SEG_CLOSE) {<br> Point4D firstPoint = arrayCoords.get(0);<br> Point4D prevPoint = arrayCoords.get(arrayCoords.size() - 1);<br>
Coordinate pCoords = prevPoint.getAsCoordinate();<br> LineSegment l = new LineSegment(pCoords, firstPoint.getAsCoordinate());<br> lineSegments.add(l);<br> parts.add(new Part(numGeometries, lineSegments));<br>
logger.debug("End of part " + numGeometries);<br> lineSegments = new ArrayList<LineSegment>();<br> }<br> theIterator.next();<br> pointIndex++;<br>
// if there's no other point add the last part to the returned ones<br> if (theType == PathIterator.SEG_LINETO && theIterator.isDone()) {<br> parts.add(new Part(numGeometries, lineSegments));<br>
logger.debug("End of last geometry's part " + numGeometries);<br> }<br> }<br> if (logger.isDebugEnabled()) {<br> logger.debug("Feature " + feature.getID() + " contains " + numGeometries + " parts");<br>
}<br> return parts;<br> }<br><br>Best regards,<br>Flavio<br><br><div class="gmail_quote">2010/2/2 Francisco José Peñarrubia <span dir="ltr"><<a href="mailto:fpenarru@gmail.com">fpenarru@gmail.com</a>></span><br>
<blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">Hi Flavio.<br>
<br>
You have to options: slow and quick, easy and a bit more difficult.<br>
The easy and slow is to convert your IGeometry to JTS Geometry with<br>
method "toJTS".<br>
The quick is to use PathIterator. You can see code from extCAD =><br>
IntersectionPointSnapper. Have a look to method getLineIntersection to<br>
see an example:<br>
<br>
public ArrayList getLineIntersection(IGeometry g, Coordinate c,<br>
double tol) {<br>
// return gp.intersects(r);<br>
// Más exacto<br>
boolean bool = false;<br>
ArrayList lineSegments = new ArrayList();<br>
int theType;<br>
// Use this array to store segment coordinate data<br>
double[] theData = new double[6];<br>
PathIterator theIterator;<br>
<br>
theIterator = g.getPathIterator(null, FConverter.FLATNESS);<br>
ArrayList arrayCoords = new ArrayList();<br>
while (!theIterator.isDone()) {<br>
theType = theIterator.currentSegment(theData);<br>
if (theType == PathIterator.SEG_MOVETO) {<br>
arrayCoords.add(new Point2D.Double(theData[0], theData[1]));<br>
} else if (theType == PathIterator.SEG_LINETO) {<br>
arrayCoords.add(new Point2D.Double(theData[0], theData[1]));<br>
Point2D pAnt = (Point2D) arrayCoords<br>
.get(arrayCoords.size() - 2);<br>
LineSegment l = new LineSegment(pAnt.getX(), pAnt.getY(),<br>
theData[0], theData[1]);<br>
if (l.distancePerpendicular(c) < tol) {<br>
bool = true;<br>
lineSegments.add(l);<br>
}<br>
} else if (theType == PathIterator.SEG_CLOSE) {<br>
Point2D firstPoint = (Point2D) arrayCoords.get(0);<br>
Point2D pAnt = (Point2D) arrayCoords<br>
.get(arrayCoords.size() - 1);<br>
LineSegment l = new LineSegment(pAnt.getX(), pAnt.getY(),<br>
firstPoint.getX(), firstPoint.getY());<br>
if (l.distancePerpendicular(c) < tol) {<br>
bool = true;<br>
lineSegments.add(l);<br>
}<br>
}<br>
theIterator.next();<br>
}<br>
return lineSegments;<br>
}<br>
<br>
Hope this helps.<br>
<br>
Fran Peñarrubia<br>
<a href="http://www.scolab.es" target="_blank">www.scolab.es</a><br>
<br>
Flavio Pompermaier escribió:<br>
<div class="im">> Thank you all for the quick replies,<br>
> but unfortunately I need parts enlighting, also if the multi-part<br>
> geometry is not splitted into many parts.<br>
> I think I'll implement such a functionality but I don't know where to<br>
> start..could someone give me some hint and<br>
> save me some work...??<br>
><br>
> Thanks in advance,<br>
> Flavio<br>
><br>
> 2010/2/1 Simon Cropper (Botanicus Australia Pty Ltd)<br>
> <<a href="mailto:scropper@botanicusaustralia.com.au">scropper@botanicusaustralia.com.au</a><br>
</div><div><div></div><div class="h5">> <mailto:<a href="mailto:scropper@botanicusaustralia.com.au">scropper@botanicusaustralia.com.au</a>>><br>
><br>
> Flavio,<br>
><br>
> gvSIG does not have the ability to split multi-part polygons so<br>
> each of<br>
> the "parts" can be manipulated seprately.<br>
><br>
> The Sextante 0.5 Plug-in has a routine though called "Separate<br>
> multi-part features" under the menu "Tools for Cector layers".<br>
><br>
> This creates a new file where any multi-part polygon is split into its<br>
> component parts.<br>
><br>
> If you do not have Sextante 0.5 running you can find the instructions<br>
> for installation here...<br>
> <a href="https://gvsig.org/web/projects/contrib/community-doc/pub/test-docs/getting-sextante-0-5-to-work-with-gvsig-version-1-9-bn-1253/" target="_blank">https://gvsig.org/web/projects/contrib/community-doc/pub/test-docs/getting-sextante-0-5-to-work-with-gvsig-version-1-9-bn-1253/</a><br>
><br>
> Cheers Simon<br>
><br>
> Simon Cropper<br>
> Botanicus Australia Pty Ltd<br>
> PO Box 160, Sunshine, Victoria 3020.<br>
> P: 9311 5822. M: 041 830 3437.<br>
> mailto: <a href="mailto:scropper@botanicusaustralia.com.au">scropper@botanicusaustralia.com.au</a><br>
> <mailto:<a href="mailto:scropper@botanicusaustralia.com.au">scropper@botanicusaustralia.com.au</a>><br>
> <mailto:<a href="mailto:scropper@botanicusaustralia.com.au">scropper@botanicusaustralia.com.au</a><br>
> <mailto:<a href="mailto:scropper@botanicusaustralia.com.au">scropper@botanicusaustralia.com.au</a>>><br>
> web: <a href="http://www.botanicusaustralia.com.au" target="_blank">www.botanicusaustralia.com.au</a><br>
> <<a href="http://www.botanicusaustralia.com.au" target="_blank">http://www.botanicusaustralia.com.au</a>><br>
> <<a href="http://www.botanicusaustralia.com.au" target="_blank">http://www.botanicusaustralia.com.au</a>><br>
><br>
><br>
> On 2/02/2010 3:13 AM, Flavio Pompermaier wrote:<br>
> > Hi to all,<br>
> > I'd like to know if anybody has ever encountered the problem I<br>
> have to<br>
> > face with: I've multipart geometries on which I must do some work on<br>
> > theri single parts,<br>
> > like reordering, enlighting, union, splitting and similar stuff.<br>
> Does<br>
> > gvSIG have the knowledge of "parts" concept from an editing<br>
> point of view?<br>
> > Could it be introduced without a great effort? And if so, where<br>
> should<br>
> > I start from with the code?<br>
> ><br>
> > Any help is appreciated!<br>
> > Flavio<br>
> ><br>
> ><br>
> > _______________________________________________<br>
> > Gvsig_internacional mailing list<br>
> > <a href="mailto:Gvsig_internacional@listserv.gva.es">Gvsig_internacional@listserv.gva.es</a><br>
</div></div>> <mailto:<a href="mailto:Gvsig_internacional@listserv.gva.es">Gvsig_internacional@listserv.gva.es</a>><br>
<div class="im">> > <a href="http://listserv.gva.es/cgi-bin/mailman/listinfo/gvsig_internacional" target="_blank">http://listserv.gva.es/cgi-bin/mailman/listinfo/gvsig_internacional</a><br>
> ><br>
> _______________________________________________<br>
> Gvsig_internacional mailing list<br>
> <a href="mailto:Gvsig_internacional@listserv.gva.es">Gvsig_internacional@listserv.gva.es</a><br>
</div>> <mailto:<a href="mailto:Gvsig_internacional@listserv.gva.es">Gvsig_internacional@listserv.gva.es</a>><br>
<div><div></div><div class="h5">> <a href="http://listserv.gva.es/cgi-bin/mailman/listinfo/gvsig_internacional" target="_blank">http://listserv.gva.es/cgi-bin/mailman/listinfo/gvsig_internacional</a><br>
><br>
><br>
> ------------------------------------------------------------------------<br>
><br>
> _______________________________________________<br>
> Gvsig_internacional mailing list<br>
> <a href="mailto:Gvsig_internacional@listserv.gva.es">Gvsig_internacional@listserv.gva.es</a><br>
> <a href="http://listserv.gva.es/cgi-bin/mailman/listinfo/gvsig_internacional" target="_blank">http://listserv.gva.es/cgi-bin/mailman/listinfo/gvsig_internacional</a><br>
><br>
<br>
_______________________________________________<br>
Gvsig_internacional mailing list<br>
<a href="mailto:Gvsig_internacional@listserv.gva.es">Gvsig_internacional@listserv.gva.es</a><br>
<a href="http://listserv.gva.es/cgi-bin/mailman/listinfo/gvsig_internacional" target="_blank">http://listserv.gva.es/cgi-bin/mailman/listinfo/gvsig_internacional</a><br>
</div></div></blockquote></div><br>