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