[fdo-users] MPolygon <-> FDO

Gavin Cramer gavin.cramer at autodesk.com
Thu Mar 6 12:07:43 EST 2008


Howdy, Dennis.

If a ring's starting and ending positions were imperfectly latched in the MPolygon data, it would cause this problem.  The same can be said for the linear case, though you did not experience it.

To avoid this, it would be a good precaution to add code to coerce the starting and ending positions of each ring to match exactly.  That is, the last position of the last curve segment should be assigned as a copy of the first position of the first curve segment.

Gavin



-----Original Message-----
From: fdo-users-bounces at lists.osgeo.org [mailto:fdo-users-bounces at lists.osgeo.org] On Behalf Of djonio
Sent: Thursday, March 06, 2008 9:46 AM
To: fdo-users at lists.osgeo.org
Subject: [fdo-users] MPolygon <-> FDO


Howdy,

I am trying to "FDOisize" a Map3d MPolygon object. The linear case is
trivial. However, my users wish to use arcs. At least to me, this is NOT
trivial. The following works in cases where the CircularArcSegment is not
the first segment drawn in the MPolygon. When it is drawn first the failure
is in the IRing ring = fgf.CreateRing(CurveSegmentColl); statement(says the
ring is not closed.) Also, if a create a MPolygon from two(2) arcs ... it
fails.

I am open to any and all suggestions and will send the entire project if
that helps.

dennis

        public static IGeometry GeometryInterfaceFromMPolygon(MPolygon
mpoly)
        {
            IGeometry rtn_IGeometry = null;
            IRing irExternal = null;
            RingCollection RingColl = new RingCollection();
            CurveSegmentCollection CurveSegmentColl = new
CurveSegmentCollection();
            FgfGeometryFactory fgf = new FgfGeometryFactory();
            if (IsItACurvePolygon(mpoly) == true)
            {
                ICircularArcSegment aCircArcSeg;
                ILineStringSegment aLineStringSeg;
                DirectPositionCollection DirectPositionColl = new
DirectPositionCollection();
                int loops = mpoly.NumMPolygonLoops;
                for (int i = 0; i < loops; i++)
                {
                    MPolygonLoop mPolygonLoop = mpoly.GetMPolygonLoopAt(i);
                    for (int j = 0; j < mPolygonLoop.Count - 1; j++)
                    {
                        aCircArcSeg = null;
                        aLineStringSeg = null;
                        BulgeVertex bv = mPolygonLoop[j];
                        double Vbulge = bv.Bulge;
                        if (Vbulge != 0.0)
                        {
                            CircularArc2d ca2d = new
CircularArc2d(bv.Vertex, mPolygonLoop[j + 1].Vertex, bv.Bulge, false);
                            DirectPositionImpl dpi_start = new
DirectPositionImpl(ca2d.StartPoint.X, ca2d.StartPoint.Y);
                            DirectPositionImpl dpi_end = new
DirectPositionImpl(ca2d.EndPoint.X, ca2d.EndPoint.Y);
                            Point2d midpoint = ca2d.EvaluatePoint(0.5);
                            DirectPositionImpl dpi_center = new
DirectPositionImpl(midpoint.X, midpoint.Y);
                            aCircArcSeg =
fgf.CreateCircularArcSegment(dpi_start, dpi_center, dpi_end);
                        }
                        else
                        {
                            DirectPositionColl.Clear();
                            DirectPositionImpl seg_s = new
DirectPositionImpl(bv.Vertex.X, bv.Vertex.Y);
                            DirectPositionColl.Add(seg_s);
                            DirectPositionImpl seg_e = new
DirectPositionImpl(mPolygonLoop[j + 1].Vertex.X, mPolygonLoop[j +
1].Vertex.Y);
                            DirectPositionColl.Add(seg_e);
                            aLineStringSeg =
fgf.CreateLineStringSegment(DirectPositionColl);
                        }

                        if (aLineStringSeg != null)
                            CurveSegmentColl.Add(aLineStringSeg);
                        else
                            CurveSegmentColl.Add(aCircArcSeg);
                    } // for vertex count

                    IRing ring = fgf.CreateRing(CurveSegmentColl);
                    if (i == 0)
                    {
                        irExternal = ring;
                    }
                    else
                    {
                        RingColl.Add(ring);
                    }
                }// for each loop in the mpolygon

                rtn_IGeometry = fgf.CreateCurvePolygon(irExternal,
RingColl);
            }
            else
            {
                double[] Ordinates;
                int OrdinateCount = 0;
                int OrdinateIndex = 0;
                ILinearRing iExternalLinearRing = null;
                ILinearRing iLinearRingInner = null;
                LinearRingCollection LinearRingColl = new
LinearRingCollection();
                int loops = mpoly.NumMPolygonLoops;
                for (int i = 0; i < loops; i++)
                {
                    MPolygonLoop mPolygonLoop = mpoly.GetMPolygonLoopAt(i);
                    // the count of 2d points
                    int verts = mPolygonLoop.Count;
                    // the count of ordinates
                    OrdinateCount = verts * 2;
                    Ordinates = new double[OrdinateCount];
                    OrdinateIndex = 0;
                    foreach (BulgeVertex bv in mPolygonLoop)
                    {
                        Point2d V2dp = bv.Vertex;
                        Ordinates[OrdinateIndex++] = V2dp.X;
                        Ordinates[OrdinateIndex++] = V2dp.Y;
                    }
                    if (i == 0)
                    {
                        iExternalLinearRing = fgf.CreateLinearRing(0,
OrdinateCount, Ordinates);
                    }
                    else
                    {
                        iLinearRingInner = fgf.CreateLinearRing(0,
OrdinateCount, Ordinates);
                        LinearRingColl.Add(iLinearRingInner);
                    }
                }
                rtn_IGeometry = fgf.CreatePolygon(iExternalLinearRing,
LinearRingColl);
            }
            return rtn_IGeometry;
        }

--
View this message in context: http://www.nabble.com/MPolygon-%3C-%3E-FDO-tp15873165s18162p15873165.html
Sent from the fdo-users mailing list archive at Nabble.com.

_______________________________________________
fdo-users mailing list
fdo-users at lists.osgeo.org
http://lists.osgeo.org/mailman/listinfo/fdo-users


More information about the fdo-users mailing list