[fdo-users] MPolygon <-> FDO

Jonio, Dennis (Aviation) DJonio at miami-airport.com
Fri Mar 7 07:11:44 EST 2008


Gavin,
I have gone back and attempted to "coerce the starting and ending
positions" I am not sure if my implementation is what you had in mind
but it is my interpretation. I still does not work with two(2) arcs and
again the case of a starting arc and any number of vertices.

I have been working with Dongjin Xing - Developer Technical Services -
Case # 1239296 and he is getting similar results.

We have a conference call this AM and maybe we will be able to find a
solution.


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);
                    //
                    Point2d[] pts = new Point2d[mPolygonLoop.Count];
                    double[] blgs = new double[mPolygonLoop.Count];
                    int z = 0;
                    for (; z < mPolygonLoop.Count; z++)
                    {
                        if (z == mPolygonLoop.Count - 1)
                            pts[z] = mPolygonLoop[0].Vertex;
                        else
                            pts[z] = mPolygonLoop[z].Vertex;
                        blgs[z] = mPolygonLoop[z].Bulge;
                    }

                    for (int j = 0; j < mPolygonLoop.Count - 1; j++)
                    {
                        aCircArcSeg = null;
                        aLineStringSeg = null;
                        double theBulge = blgs[j];
                        if (theBulge != 0.0)
                        {
                            CircularArc2d ca2d = new
CircularArc2d(pts[j], pts[j + 1], theBulge, 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(pts[j].X, pts[j].Y);
                            DirectPositionColl.Add(seg_s);
                            DirectPositionImpl seg_e = new
DirectPositionImpl(pts[j + 1].X, pts[j + 1].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;
        }
-----Original Message-----
From: fdo-users-bounces at lists.osgeo.org
[mailto:fdo-users-bounces at lists.osgeo.org] On Behalf Of Gavin Cramer
Sent: Thursday, March 06, 2008 7:17 PM
To: FDO Users Mail List
Subject: RE: [fdo-users] MPolygon <-> FDO

Hello again, Dennis.  That comparison of Point2D objects may call code
that includes internal distance calculations and comparisons with
tolerances.  The definitive test would be to check the X and Y ordinates
directly.

Gavin



More information about the fdo-users mailing list