[fdo-users] MPolygon <-> FDO

Maksim Sestic max at geoinova.com
Thu Mar 6 10:06:23 EST 2008


Hi Dennis,

As you said, this is not trivial :-) I have a solution that converts
ObjectARX Arcs to LineStrings, using given number of segments. Alas, the
process is irreversible and introduces about 0.2% total surface error margin
when there're 8 segments in an arc, even less if you increase number of
segments for tesselation.

Check out latest version of  http://code.google.com/p/tf-net/ TF.NET  
(v.1.0.8). Download libraries and include Topology.IO.Dwg and
Topology.IO.Agf (if you're planning to deploy it with Autodesk Map 3D). In
case you're using plain AutoCAD and OSGeo FDO - reference Topology.IO.Fgf
instead.

Now, DwgReader reads ObjectARX entities and converts them to WKT-compatible
Geometries. Then use AgfWriter to "write" them to Autodesk's FDO MgGeometry.
WKT doesn't support arcs, therefor your arcs will get tesselated during
reading process. Just browse down the API documentation and don't hesitate
to ask if you need any assistance. You can also get the source code from
project's SVN repository.

Regards,
Maksim Sestic


djonio wrote:
> 
> 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-tp15873165s18162p15873187.html
Sent from the fdo-users mailing list archive at Nabble.com.



More information about the fdo-users mailing list