Beispiel #1
0
 internal SpatialContextInfo(ISpatialContextReader reader)
 {
     this.CoordinateSystem    = reader.GetCoordinateSystem();
     this.CoordinateSystemWkt = reader.GetCoordinateSystemWkt();
     this.Description         = reader.GetDescription();
     this.ExtentType          = reader.GetExtentType();
     this.Name        = reader.GetName();
     this.XYTolerance = reader.GetXYTolerance();
     this.ZTolerance  = reader.GetZTolerance();
     this.IsActive    = reader.IsActive();
     try
     {
         byte[] bGeom = reader.GetExtent();
         if (bGeom != null)
         {
             using (FgfGeometryFactory factory = new FgfGeometryFactory())
                 using (IGeometry geom = factory.CreateGeometryFromFgf(bGeom))
                 {
                     this.ExtentGeometryText = geom.Text;
                 }
         }
     }
     catch
     {
         this.ExtentGeometryText = null;
     }
 }
 internal SpatialContextInfo(ISpatialContextReader reader)
 {
     this.CoordinateSystem = reader.GetCoordinateSystem();
     this.CoordinateSystemWkt = reader.GetCoordinateSystemWkt();
     this.Description = reader.GetDescription();
     this.ExtentType = reader.GetExtentType();
     this.Name = reader.GetName();
     this.XYTolerance = reader.GetXYTolerance();
     this.ZTolerance = reader.GetZTolerance();
     this.IsActive = reader.IsActive();
     try
     {
         byte[] bGeom = reader.GetExtent();
         if (bGeom != null)
         {
             using (FgfGeometryFactory factory = new FgfGeometryFactory())
             using (IGeometry geom = factory.CreateGeometryFromFgf(bGeom))
             {
                 this.ExtentGeometryText = geom.Text;
             }
         }
     }
     catch
     {
         this.ExtentGeometryText = null;
     }
 }
        public static OSGeo.FDO.Geometry.IGeometry GetGeometry(IFeatureReader reader, string name)
        {
            byte[] geometryBytes = reader.GetGeometry(name);

            FgfGeometryFactory geometryFactory = new FgfGeometryFactory();
            IGeometry          geometry        = geometryFactory.CreateGeometryFromFgf(geometryBytes);

            return(geometry);
        }
Beispiel #4
0
        internal FdoFeatureReader(IFeatureReader reader) : base(reader)
        {
            _internalFactory = new FgfGeometryFactory();
            _classDefinition = reader.GetClassDefinition();
            _ptypes          = new Dictionary <string, FdoPropertyType>();
            _associations    = new Dictionary <string, string>();
            _ordinals        = new Dictionary <string, int>();
            _types           = new Type[_classDefinition.Properties.Count];
            _names           = new string[_classDefinition.Properties.Count];
            List <string> geoms = new List <string>();

            for (int i = 0; i < _names.Length; i++)
            {
                PropertyDefinition pd = _classDefinition.Properties[i];
                _names[i] = pd.Name;
                string name = _names[i];
                _ordinals.Add(_names[i], i);

                DataPropertyDefinition      dp = pd as DataPropertyDefinition;
                GeometricPropertyDefinition gp = pd as GeometricPropertyDefinition;
                if (dp != null)
                {
                    _types[i]     = ExpressUtility.GetClrTypeFromFdoDataType(dp.DataType);
                    _ptypes[name] = ValueConverter.FromDataType(dp.DataType);
                }
                else if (gp != null)
                {
                    _types[i] = typeof(byte[]);
                    geoms.Add(gp.Name);
                    _ptypes[name]       = FdoPropertyType.Geometry;
                    _associations[name] = gp.SpatialContextAssociation;
                }
                else if (pd.PropertyType == PropertyType.PropertyType_ObjectProperty)
                {
                    _ptypes[name] = FdoPropertyType.Object;
                }
                else if (pd.PropertyType == PropertyType.PropertyType_RasterProperty)
                {
                    _ptypes[name] = FdoPropertyType.Raster;
                    _types[i]     = typeof(IRaster);
                }
                else if (pd.PropertyType == PropertyType.PropertyType_AssociationProperty)
                {
                    _ptypes[name] = FdoPropertyType.Association;
                }
            }
            _geometryNames = geoms.ToArray();
            if (_classDefinition is FeatureClass && (_classDefinition as FeatureClass).GeometryProperty != null)
            {
                _defaultGeometryName = (_classDefinition as FeatureClass).GeometryProperty.Name;
            }
            else if (geoms.Count > 0)
            {
                _defaultGeometryName = geoms[0];
            }
        }
        private static IMultiPolygon FlattenMultiPolygon(IMultiPolygon mpoly, FgfGeometryFactory factory)
        {
            PolygonCollection polys = new PolygonCollection();

            for (int i = 0; i < mpoly.Count; i++)
            {
                polys.Add(FlattenPolygon(mpoly[i], factory));
            }
            return(factory.CreateMultiPolygon(polys));
        }
        private static IMultiPoint FlattenMultiPoint(IMultiPoint mpoint, FgfGeometryFactory factory)
        {
            PointCollection points = new PointCollection();

            for (int i = 0; i < mpoint.Count; i++)
            {
                points.Add(FlattenPoint(mpoint[i], factory));
            }
            return(factory.CreateMultiPoint(points));
        }
        private static IMultiGeometry FlattenMultiGeometry(IMultiGeometry mgeom, FgfGeometryFactory factory)
        {
            GeometryCollection geometries = new GeometryCollection();

            for (int i = 0; i < mgeom.Count; i++)
            {
                geometries.Add(Flatten(mgeom[i], factory));
            }
            return(factory.CreateMultiGeometry(geometries));
        }
        private static ICurveString FlattenCurveString(ICurveString curveStr, FgfGeometryFactory factory)
        {
            CurveSegmentCollection curveSegs = new CurveSegmentCollection();

            for (int i = 0; i < curveStr.Count; i++)
            {
                curveSegs.Add(FlattenCurveSegment(curveStr[i], factory));
            }
            return(factory.CreateCurveString(curveSegs));
        }
        private static IRing FlattenRing(IRing ring, FgfGeometryFactory factory)
        {
            CurveSegmentCollection curves = new CurveSegmentCollection();

            foreach (ICurveSegmentAbstract curve in ring.CurveSegments)
            {
                curves.Add(FlattenCurveSegment(curve, factory));
            }
            return(factory.CreateRing(curves));
        }
        private static ICurvePolygon FlattenCurvePolygon(ICurvePolygon curvePolygon, FgfGeometryFactory factory)
        {
            IRing          extRing  = FlattenRing(curvePolygon.ExteriorRing, factory);
            RingCollection intRings = new RingCollection();

            for (int i = 0; i < curvePolygon.InteriorRingCount; i++)
            {
                intRings.Add(FlattenRing(curvePolygon.get_InteriorRing(i), factory));
            }
            return(factory.CreateCurvePolygon(extRing, intRings));
        }
 public GeometryVisualizer()
 {
     InitializeComponent();
     _geomFactory = new FgfGeometryFactory();
     _layer       = new SharpMap.Layers.VectorLayer("Preview");
     _mapCtl      = new SharpMap.Forms.MapImage();
     _mapCtl.Map  = new SharpMap.Map();
     _mapCtl.Map.Layers.Add(_layer);
     _mapCtl.Dock = DockStyle.Fill;
     mapPanel.Controls.Add(_mapCtl);
 }
 public GeometryVisualizer()
 {
     InitializeComponent();
     _geomFactory = new FgfGeometryFactory();
     _layer = new SharpMap.Layers.VectorLayer("Preview");
     _mapCtl = new SharpMap.Forms.MapImage();
     _mapCtl.Map = new SharpMap.Map();
     _mapCtl.Map.Layers.Add(_layer);
     _mapCtl.Dock = DockStyle.Fill;
     mapPanel.Controls.Add(_mapCtl);
 }
        public static GeoAPI.Geometries.IGeometry ConvertTo(OSGeo.FDO.Geometry.IGeometry geometry)
        {
            //GisSharpBlog.NetTopologySuite.IO.WKTReader wktReader = new GisSharpBlog.NetTopologySuite.IO.WKTReader();
            //GeoAPI.Geometries.IGeometry ntsGeometry = wktReader.Read( geometry.Text );
            //return ntsGeometry;

            GisSharpBlog.NetTopologySuite.IO.WKBReader wkbReader = new GisSharpBlog.NetTopologySuite.IO.WKBReader();
            FgfGeometryFactory geometryFactory = new FgfGeometryFactory();

            GeoAPI.Geometries.IGeometry ntsGeometry = wkbReader.Read(geometryFactory.GetWkb(geometry));
            return(ntsGeometry);
        }
 /// <summary>
 /// Gets the FGF binary from the given text
 /// </summary>
 /// <param name="str"></param>
 /// <returns></returns>
 public static byte[] GetFgf(string str)
 {
     byte[] fgf = null;
     using (FgfGeometryFactory factory = new FgfGeometryFactory())
     {
         using (IGeometry geom = factory.CreateGeometry(str))
         {
             fgf = factory.GetFgf(geom);
         }
     }
     return(fgf);
 }
        private static ILineString FlattenLineString(ILineString lineStr, FgfGeometryFactory factory)
        {
            double[] lineStrOrdinates = new double[lineStr.Count * 2];
            int      i = 0;

            foreach (IDirectPosition pos in lineStr.Positions)
            {
                lineStrOrdinates[i]     = pos.X;
                lineStrOrdinates[i + 1] = pos.Y;
                i += 2;
            }

            return(factory.CreateLineString(FDO_DIM_XY, lineStrOrdinates.Length, lineStrOrdinates));
        }
        /// <summary>
        /// Loads a FDO XML configuration document
        /// </summary>
        /// <param name="xmlFile"></param>
        /// <returns></returns>
        public static FdoDataStoreConfiguration FromFile(string xmlFile)
        {
            using (var fact = new FgfGeometryFactory())
                using (var ios = new IoFileStream(xmlFile, "r"))
                {
                    using (var reader = new XmlReader(ios))
                    {
                        List <SpatialContextInfo> contexts = new List <SpatialContextInfo>();
                        using (var scReader = new XmlSpatialContextReader(reader))
                        {
                            while (scReader.ReadNext())
                            {
                                var sc = new SpatialContextInfo();
                                sc.CoordinateSystem    = scReader.GetCoordinateSystem();
                                sc.CoordinateSystemWkt = scReader.GetCoordinateSystemWkt();
                                sc.Description         = scReader.GetDescription();
                                sc.ExtentType          = scReader.GetExtentType();
                                if (sc.ExtentType == OSGeo.FDO.Commands.SpatialContext.SpatialContextExtentType.SpatialContextExtentType_Static)
                                {
                                    using (var geom = fact.CreateGeometryFromFgf(scReader.GetExtent()))
                                    {
                                        sc.ExtentGeometryText = geom.Text;
                                    }
                                }
                                sc.IsActive    = scReader.IsActive();
                                sc.Name        = scReader.GetName();
                                sc.XYTolerance = scReader.GetXYTolerance();
                                sc.ZTolerance  = scReader.GetZTolerance();

                                contexts.Add(sc);
                            }
                        }

                        ios.Reset();

                        var schemas = new FeatureSchemaCollection(null);
                        schemas.ReadXml(ios);

                        ios.Reset();

                        var mappings = new PhysicalSchemaMappingCollection();
                        mappings.ReadXml(ios);

                        ios.Close();

                        return(new FdoDataStoreConfiguration(schemas, contexts.ToArray(), mappings));
                    }
                }
        }
Beispiel #17
0
 /// <summary>
 /// Forces the given geometry to be WKB compliant. If necessary, a <see cref="Flatten"/> call
 /// will be made on the geometry.
 /// </summary>
 /// <param name="geom"></param>
 /// <param name="fact"></param>
 /// <returns></returns>
 public static IGeometry ForceWkb(IGeometry geom, FgfGeometryFactory fact)
 {
     byte [] wkb = null;
     try
     {
         wkb = fact.GetWkb(geom);
     }
     catch
     {
         using (IGeometry wg = Flatten(geom, fact))
         {
             wkb = fact.GetWkb(geom);
         }
     }
     return fact.CreateGeometryFromWkb(wkb);
 }
 /// <summary>
 /// Forces the given geometry to be WKB compliant. If necessary, a <see cref="Flatten"/> call
 /// will be made on the geometry.
 /// </summary>
 /// <param name="geom"></param>
 /// <param name="fact"></param>
 /// <returns></returns>
 public static IGeometry ForceWkb(IGeometry geom, FgfGeometryFactory fact)
 {
     byte [] wkb = null;
     try
     {
         wkb = fact.GetWkb(geom);
     }
     catch
     {
         using (IGeometry wg = Flatten(geom, fact))
         {
             wkb = fact.GetWkb(geom);
         }
     }
     return(fact.CreateGeometryFromWkb(wkb));
 }
        /// <summary>
        /// Flattens the specified geometry by stripping out the Z and M components of all ordinates
        /// within the geometry.
        /// </summary>
        /// <param name="geom">The geometry to flatten</param>
        /// <param name="factory">The geometry factory.</param>
        /// <returns>The geometry with all Z and M ordinates stripped out. If the input geometry is already 2D, then it is returned as is.</returns>
        public static IGeometry Flatten(IGeometry geom, FgfGeometryFactory factory)
        {
            int dim = geom.Dimensionality;

            //Has no Z or M ordinates, so return geometry as is.
            if (Is2D(geom))
            {
                return(geom);
            }

            switch (geom.DerivedType)
            {
            case OSGeo.FDO.Common.GeometryType.GeometryType_CurvePolygon:
                return(FlattenCurvePolygon((ICurvePolygon)geom, factory));

            case OSGeo.FDO.Common.GeometryType.GeometryType_CurveString:
                return(FlattenCurveString((ICurveString)geom, factory));

            case OSGeo.FDO.Common.GeometryType.GeometryType_LineString:
                return(FlattenLineString((ILineString)geom, factory));

            case OSGeo.FDO.Common.GeometryType.GeometryType_MultiCurvePolygon:
                return(FlattenMultiCurvePolygon((IMultiCurvePolygon)geom, factory));

            case OSGeo.FDO.Common.GeometryType.GeometryType_MultiCurveString:
                return(FlattenMultiCurveString((IMultiCurveString)geom, factory));

            case OSGeo.FDO.Common.GeometryType.GeometryType_MultiGeometry:
                return(FlattenMultiGeometry((IMultiGeometry)geom, factory));

            case OSGeo.FDO.Common.GeometryType.GeometryType_MultiLineString:
                return(FlattenMultiLineString((IMultiLineString)geom, factory));

            case OSGeo.FDO.Common.GeometryType.GeometryType_MultiPoint:
                return(FlattenMultiPoint((IMultiPoint)geom, factory));

            case OSGeo.FDO.Common.GeometryType.GeometryType_MultiPolygon:
                return(FlattenMultiPolygon((IMultiPolygon)geom, factory));

            case OSGeo.FDO.Common.GeometryType.GeometryType_Point:
                return(FlattenPoint((IPoint)geom, factory));

            case OSGeo.FDO.Common.GeometryType.GeometryType_Polygon:
                return(FlattenPolygon((IPolygon)geom, factory));
            }
            return(null);
        }
        private static ILinearRing FlattenLinearRing(ILinearRing ring, FgfGeometryFactory factory)
        {
            //Copy exterior ring
            double[] flatRingPoints = new double[ring.Count * 2];
            int      i = 0;

            foreach (IDirectPosition pos in ring.Positions)
            {
                flatRingPoints[i]     = pos.X;
                flatRingPoints[i + 1] = pos.Y;
                i += 2;
            }

            ILinearRing flatRing = factory.CreateLinearRing(FDO_DIM_XY, flatRingPoints.Length, flatRingPoints);

            return(flatRing);
        }
        private static IPolygon FlattenPolygon(IPolygon polygon, FgfGeometryFactory factory)
        {
            ILinearRing extRing = FlattenLinearRing(polygon.ExteriorRing, factory);

            //Copy interior rings
            LinearRingCollection intRings = new LinearRingCollection();

            for (int j = 0; j < polygon.InteriorRingCount; j++)
            {
                ILinearRing ring = polygon.GetInteriorRing(j);
                intRings.Add(FlattenLinearRing(ring, factory));
            }

            IPolygon flatPolygon = factory.CreatePolygon(extRing, intRings);

            return(flatPolygon);
        }
 /// <summary>
 /// Gets the FGF binary from the given text
 /// </summary>
 /// <param name="str"></param>
 /// <returns></returns>
 public static byte[] GetFgf(string str)
 {
     byte[] fgf = null;
     using (FgfGeometryFactory factory = new FgfGeometryFactory())
     {
         using (IGeometry geom = factory.CreateGeometry(str))
         {
             fgf = factory.GetFgf(geom);
         }
     }
     return fgf;
 }
Beispiel #23
0
 internal SdfExporter()
 {
     m_Factory = new FgfGeometryFactory();
 }
 private static ICurvePolygon FlattenCurvePolygon(ICurvePolygon curvePolygon, FgfGeometryFactory factory)
 {
     IRing extRing = FlattenRing(curvePolygon.ExteriorRing, factory);
     RingCollection intRings = new RingCollection();
     for (int i = 0; i < curvePolygon.InteriorRingCount; i++)
     {
         intRings.Add(FlattenRing(curvePolygon.get_InteriorRing(i), factory));
     }
     return factory.CreateCurvePolygon(extRing, intRings);
 }
        public static OSGeo.FDO.Geometry.IGeometry ConvertFrom(GeoAPI.Geometries.IGeometry geometry)
        {
            FgfGeometryFactory geometryFactory = new FgfGeometryFactory();

            return(geometryFactory.CreateGeometryFromWkb(geometry.AsBinary()));
        }
        private static ILineStringSegment FlattenLineStringSegment(ILineStringSegment lineStrSegment, FgfGeometryFactory factory)
        {
            double[] positions = new double[lineStrSegment.Count * 2];
            int      j         = 0;

            for (int i = 0; i < lineStrSegment.Count; i++)
            {
                IDirectPosition pos = lineStrSegment[i];
                positions[j]     = pos.X;
                positions[j + 1] = pos.Y;
                j += 2;
            }
            return(factory.CreateLineStringSegment(FDO_DIM_XY, positions.Length, positions));
        }
 private static IDirectPosition FlattenPosition(IDirectPosition pos, FgfGeometryFactory factory)
 {
     return(factory.CreatePositionXY(pos.X, pos.Y));
 }
        private static ILinearRing FlattenLinearRing(ILinearRing ring, FgfGeometryFactory factory)
        {
            //Copy exterior ring
            double[] flatRingPoints = new double[ring.Count * 2];
            int i = 0;
            foreach (IDirectPosition pos in ring.Positions)
            {
                flatRingPoints[i] = pos.X;
                flatRingPoints[i + 1] = pos.Y;
                i += 2;
            }

            ILinearRing flatRing = factory.CreateLinearRing(FDO_DIM_XY, flatRingPoints.Length, flatRingPoints);
            return flatRing;
        }
 private static IMultiGeometry FlattenMultiGeometry(IMultiGeometry mgeom, FgfGeometryFactory factory)
 {
     GeometryCollection geometries = new GeometryCollection();
     for (int i = 0; i < mgeom.Count; i++)
     {
         geometries.Add(Flatten(mgeom[i], factory));
     }
     return factory.CreateMultiGeometry(geometries);
 }
 private static IMultiLineString FlattenMultiLineString(IMultiLineString mlString, FgfGeometryFactory factory)
 {
     LineStringCollection lineStrings = new LineStringCollection();
     for (int i = 0; i < mlString.Count; i++)
     {
         lineStrings.Add(FlattenLineString(mlString[i], factory));
     }
     return factory.CreateMultiLineString(lineStrings);
 }
 private static IMultiPoint FlattenMultiPoint(IMultiPoint mpoint, FgfGeometryFactory factory)
 {
     PointCollection points = new PointCollection();
     for (int i = 0; i < mpoint.Count; i++)
     {
         points.Add(FlattenPoint(mpoint[i], factory));
     }
     return factory.CreateMultiPoint(points);
 }
 private static IMultiPolygon FlattenMultiPolygon(IMultiPolygon mpoly, FgfGeometryFactory factory)
 {
     PolygonCollection polys = new PolygonCollection();
     for (int i = 0; i < mpoly.Count; i++)
     {
         polys.Add(FlattenPolygon(mpoly[i], factory));
     }
     return factory.CreateMultiPolygon(polys);
 }
 private static IPoint FlattenPoint(IPoint point, FgfGeometryFactory factory)
 {
     return factory.CreatePoint(FDO_DIM_XY, new double[] { point.Position.X, point.Position.Y });
 }
        /// <summary>
        /// Saves this out to a FDO XML configuration document
        /// </summary>
        /// <param name="xmlFile"></param>
        public void Save(string xmlFile)
        {
            using (var fact = new FgfGeometryFactory())
                using (var ws = new IoFileStream(xmlFile, "w"))
                {
                    using (var writer = new XmlWriter(ws, true, XmlWriter.LineFormat.LineFormat_Indent))
                    {
                        //Write spatial contexts
                        if (this.SpatialContexts != null && this.SpatialContexts.Length > 0)
                        {
                            var flags = new XmlSpatialContextFlags();
                            using (var scWriter = new XmlSpatialContextWriter(writer))
                            {
                                foreach (var sc in this.SpatialContexts)
                                {
                                    //XmlSpatialContextWriter forbids writing dynamically calculated extents
                                    if (sc.ExtentType == OSGeo.FDO.Commands.SpatialContext.SpatialContextExtentType.SpatialContextExtentType_Dynamic)
                                    {
                                        continue;
                                    }

                                    scWriter.CoordinateSystem    = sc.CoordinateSystem;
                                    scWriter.CoordinateSystemWkt = sc.CoordinateSystemWkt;
                                    scWriter.Description         = sc.Description;

                                    scWriter.ExtentType = sc.ExtentType;

                                    using (var geom = fact.CreateGeometry(sc.ExtentGeometryText))
                                    {
                                        byte[] fgf = fact.GetFgf(geom);
                                        scWriter.Extent = fgf;
                                    }

                                    scWriter.Name        = sc.Name;
                                    scWriter.XYTolerance = sc.XYTolerance;
                                    scWriter.ZTolerance  = sc.ZTolerance;

                                    scWriter.WriteSpatialContext();
                                }
                            }
                        }



                        //Write logical schema
                        if (this.Schemas != null)
                        {
                            var schemas = CloneSchemas(this.Schemas);

                            schemas.WriteXml(writer);
                        }

                        //Write physical mappings
                        if (this.Mappings != null)
                        {
                            this.Mappings.WriteXml(writer);
                        }

                        writer.Close();
                    }
                    ws.Close();
                }
        }
        private static IPolygon FlattenPolygon(IPolygon polygon, FgfGeometryFactory factory)
        {
            ILinearRing extRing = FlattenLinearRing(polygon.ExteriorRing, factory);

            //Copy interior rings
            LinearRingCollection intRings = new LinearRingCollection();
            for (int j = 0; j < polygon.InteriorRingCount; j++)
            {
                ILinearRing ring = polygon.GetInteriorRing(j);
                intRings.Add(FlattenLinearRing(ring, factory));
            }

            IPolygon flatPolygon = factory.CreatePolygon(extRing, intRings);
            return flatPolygon;
        }
        /// <summary>
        /// Loads a FDO XML configuration document
        /// </summary>
        /// <param name="xmlFile"></param>
        /// <returns></returns>
        public static FdoDataStoreConfiguration FromFile(string xmlFile)
        {
            using (var fact = new FgfGeometryFactory())
            using (var ios = new IoFileStream(xmlFile, "r"))
            {
                using (var reader = new XmlReader(ios))
                {
                    List<SpatialContextInfo> contexts = new List<SpatialContextInfo>();
                    using (var scReader = new XmlSpatialContextReader(reader))
                    {
                        while (scReader.ReadNext())
                        {
                            var sc = new SpatialContextInfo();
                            sc.CoordinateSystem = scReader.GetCoordinateSystem();
                            sc.CoordinateSystemWkt = scReader.GetCoordinateSystemWkt();
                            sc.Description = scReader.GetDescription();
                            sc.ExtentType = scReader.GetExtentType();
                            if (sc.ExtentType == OSGeo.FDO.Commands.SpatialContext.SpatialContextExtentType.SpatialContextExtentType_Static)
                            {
                                using (var geom = fact.CreateGeometryFromFgf(scReader.GetExtent()))
                                {
                                    sc.ExtentGeometryText = geom.Text;
                                }
                            }
                            sc.IsActive = scReader.IsActive();
                            sc.Name = scReader.GetName();
                            sc.XYTolerance = scReader.GetXYTolerance();
                            sc.ZTolerance = scReader.GetZTolerance();

                            contexts.Add(sc);
                        }
                    }

                    ios.Reset();

                    var schemas = new FeatureSchemaCollection(null);
                    schemas.ReadXml(ios);

                    ios.Reset();

                    var mappings = new PhysicalSchemaMappingCollection();
                    mappings.ReadXml(ios);

                    ios.Close();

                    return new FdoDataStoreConfiguration(schemas, contexts.ToArray(), mappings);
                }
            }
        }
 private static IDirectPosition FlattenPosition(IDirectPosition pos, FgfGeometryFactory factory)
 {
     return factory.CreatePositionXY(pos.X, pos.Y);
 }
 private static IPoint FlattenPoint(IPoint point, FgfGeometryFactory factory)
 {
     return(factory.CreatePoint(FDO_DIM_XY, new double[] { point.Position.X, point.Position.Y }));
 }
        private static ICurveSegmentAbstract FlattenCurveSegment(ICurveSegmentAbstract curveSegment, FgfGeometryFactory factory)
        {
            switch (curveSegment.DerivedType)
            {
            case OSGeo.FDO.Common.GeometryComponentType.GeometryComponentType_CircularArcSegment:
                return(FlattenCircularArcSegment((ICircularArcSegment)curveSegment, factory));

            case OSGeo.FDO.Common.GeometryComponentType.GeometryComponentType_LinearRing:
                throw new NotSupportedException("Unable to flatten this segment type");     //Uh, ILinearRing doesn't inherit from ICurveSegmentAbstract

            case OSGeo.FDO.Common.GeometryComponentType.GeometryComponentType_LineStringSegment:
                return(FlattenLineStringSegment((ILineStringSegment)curveSegment, factory));

            case OSGeo.FDO.Common.GeometryComponentType.GeometryComponentType_Ring:
                throw new NotSupportedException("Unable to flatten this segment type");     //Uh, IRing doesn't inherit from ICurveSegmentAbstract
            }
            throw new ArgumentException("Unknown curve segment type");
        }
 private static IMultiCurveString FlattenMultiCurveString(IMultiCurveString mcString, FgfGeometryFactory factory)
 {
     CurveStringCollection curveStrings = new CurveStringCollection();
     for (int i = 0; i < mcString.Count; i++)
     {
         curveStrings.Add(FlattenCurveString(mcString[i], factory));
     }
     return factory.CreateMultiCurveString(curveStrings);
 }
 private static ICircularArcSegment FlattenCircularArcSegment(ICircularArcSegment circularArc, FgfGeometryFactory factory)
 {
     return(factory.CreateCircularArcSegment(
                FlattenPosition(circularArc.StartPosition, factory),
                FlattenPosition(circularArc.MidPoint, factory),
                FlattenPosition(circularArc.EndPosition, factory)));
 }
 private static IMultiCurvePolygon FlattenMultiCurvePolygon(IMultiCurvePolygon mcPolygon, FgfGeometryFactory factory)
 {
     CurvePolygonCollection curvePolygons = new CurvePolygonCollection();
     for (int i = 0; i < mcPolygon.Count; i++)
     {
         curvePolygons.Add(FlattenCurvePolygon(mcPolygon[i], factory));
     }
     return factory.CreateMultiCurvePolygon(curvePolygons);
 }
 private static ICurveString FlattenCurveString(ICurveString curveStr, FgfGeometryFactory factory)
 {
     CurveSegmentCollection curveSegs = new CurveSegmentCollection();
     for (int i = 0; i < curveStr.Count; i++)
     {
         curveSegs.Add(FlattenCurveSegment(curveStr[i], factory));
     }
     return factory.CreateCurveString(curveSegs);
 }
        private static IMultiLineString FlattenMultiLineString(IMultiLineString mlString, FgfGeometryFactory factory)
        {
            LineStringCollection lineStrings = new LineStringCollection();

            for (int i = 0; i < mlString.Count; i++)
            {
                lineStrings.Add(FlattenLineString(mlString[i], factory));
            }
            return(factory.CreateMultiLineString(lineStrings));
        }
 private static ICurveSegmentAbstract FlattenCurveSegment(ICurveSegmentAbstract curveSegment, FgfGeometryFactory factory)
 {
     switch (curveSegment.DerivedType)
     {
         case OSGeo.FDO.Common.GeometryComponentType.GeometryComponentType_CircularArcSegment:
             return FlattenCircularArcSegment((ICircularArcSegment)curveSegment, factory);
         case OSGeo.FDO.Common.GeometryComponentType.GeometryComponentType_LinearRing:
             throw new NotSupportedException("Unable to flatten this segment type"); //Uh, ILinearRing doesn't inherit from ICurveSegmentAbstract
         case OSGeo.FDO.Common.GeometryComponentType.GeometryComponentType_LineStringSegment:
             return FlattenLineStringSegment((ILineStringSegment)curveSegment, factory);
         case OSGeo.FDO.Common.GeometryComponentType.GeometryComponentType_Ring:
             throw new NotSupportedException("Unable to flatten this segment type"); //Uh, IRing doesn't inherit from ICurveSegmentAbstract
     }
     throw new ArgumentException("Unknown curve segment type");
 }
 private static ILineStringSegment FlattenLineStringSegment(ILineStringSegment lineStrSegment, FgfGeometryFactory factory)
 {
     double[] positions = new double[lineStrSegment.Count * 2];
     int j = 0;
     for (int i = 0; i < lineStrSegment.Count; i++)
     {
         IDirectPosition pos = lineStrSegment[i];
         positions[j] = pos.X;
         positions[j+1] = pos.Y;
         j += 2;
     }
     return factory.CreateLineStringSegment(FDO_DIM_XY, positions.Length, positions);
 }
Beispiel #47
0
 internal SdfExporter()
 {
     m_Factory = new FgfGeometryFactory();
 }
        private static IMultiCurveString FlattenMultiCurveString(IMultiCurveString mcString, FgfGeometryFactory factory)
        {
            CurveStringCollection curveStrings = new CurveStringCollection();

            for (int i = 0; i < mcString.Count; i++)
            {
                curveStrings.Add(FlattenCurveString(mcString[i], factory));
            }
            return(factory.CreateMultiCurveString(curveStrings));
        }
 private static ICircularArcSegment FlattenCircularArcSegment(ICircularArcSegment circularArc, FgfGeometryFactory factory)
 {
     return factory.CreateCircularArcSegment(
         FlattenPosition(circularArc.StartPosition, factory),
         FlattenPosition(circularArc.MidPoint, factory),
         FlattenPosition(circularArc.EndPosition, factory));
 }
        private static IMultiCurvePolygon FlattenMultiCurvePolygon(IMultiCurvePolygon mcPolygon, FgfGeometryFactory factory)
        {
            CurvePolygonCollection curvePolygons = new CurvePolygonCollection();

            for (int i = 0; i < mcPolygon.Count; i++)
            {
                curvePolygons.Add(FlattenCurvePolygon(mcPolygon[i], factory));
            }
            return(factory.CreateMultiCurvePolygon(curvePolygons));
        }
        /// <summary>
        /// Flattens the specified geometry by stripping out the Z and M components of all ordinates
        /// within the geometry.
        /// </summary>
        /// <param name="geom">The geometry to flatten</param>
        /// <param name="factory">The geometry factory.</param>
        /// <returns>The geometry with all Z and M ordinates stripped out. If the input geometry is already 2D, then it is returned as is.</returns>
        public static IGeometry Flatten(IGeometry geom, FgfGeometryFactory factory)
        {
            int dim = geom.Dimensionality;

            //Has no Z or M ordinates, so return geometry as is.
            if (Is2D(geom))
                return geom;

            switch (geom.DerivedType)
            {
                case OSGeo.FDO.Common.GeometryType.GeometryType_CurvePolygon:
                    return FlattenCurvePolygon((ICurvePolygon)geom, factory);
                case OSGeo.FDO.Common.GeometryType.GeometryType_CurveString:
                    return FlattenCurveString((ICurveString)geom, factory);
                case OSGeo.FDO.Common.GeometryType.GeometryType_LineString:
                    return FlattenLineString((ILineString)geom, factory);
                case OSGeo.FDO.Common.GeometryType.GeometryType_MultiCurvePolygon:
                    return FlattenMultiCurvePolygon((IMultiCurvePolygon)geom, factory);
                case OSGeo.FDO.Common.GeometryType.GeometryType_MultiCurveString:
                    return FlattenMultiCurveString((IMultiCurveString)geom, factory);
                case OSGeo.FDO.Common.GeometryType.GeometryType_MultiGeometry:
                    return FlattenMultiGeometry((IMultiGeometry)geom, factory);
                case OSGeo.FDO.Common.GeometryType.GeometryType_MultiLineString:
                    return FlattenMultiLineString((IMultiLineString)geom, factory);
                case OSGeo.FDO.Common.GeometryType.GeometryType_MultiPoint:
                    return FlattenMultiPoint((IMultiPoint)geom, factory);
                case OSGeo.FDO.Common.GeometryType.GeometryType_MultiPolygon:
                    return FlattenMultiPolygon((IMultiPolygon)geom, factory);
                case OSGeo.FDO.Common.GeometryType.GeometryType_Point:
                    return FlattenPoint((IPoint)geom, factory);
                case OSGeo.FDO.Common.GeometryType.GeometryType_Polygon:
                    return FlattenPolygon((IPolygon)geom, factory);
            }
            return null;
        }
        private static ILineString FlattenLineString(ILineString lineStr, FgfGeometryFactory factory)
        {
            double[] lineStrOrdinates = new double[lineStr.Count * 2];
            int i = 0;
            foreach (IDirectPosition pos in lineStr.Positions)
            {
                lineStrOrdinates[i] = pos.X;
                lineStrOrdinates[i + 1] = pos.Y;
                i += 2;
            }

            return factory.CreateLineString(FDO_DIM_XY, lineStrOrdinates.Length, lineStrOrdinates);
        }
        /// <summary>
        /// Saves this out to a FDO XML configuration document
        /// </summary>
        /// <param name="xmlFile"></param>
        public void Save(string xmlFile)
        {
            using (var fact = new FgfGeometryFactory())
            using (var ws = new IoFileStream(xmlFile, "w"))
            {
                using (var writer = new XmlWriter(ws, true, XmlWriter.LineFormat.LineFormat_Indent))
                {
                    //Write spatial contexts
                    if (this.SpatialContexts != null && this.SpatialContexts.Length > 0)
                    {
                        var flags = new XmlSpatialContextFlags();
                        using (var scWriter = new XmlSpatialContextWriter(writer))
                        {
                            foreach (var sc in this.SpatialContexts)
                            {
                                //XmlSpatialContextWriter forbids writing dynamically calculated extents
                                if (sc.ExtentType == OSGeo.FDO.Commands.SpatialContext.SpatialContextExtentType.SpatialContextExtentType_Dynamic)
                                    continue;

                                scWriter.CoordinateSystem = sc.CoordinateSystem;
                                scWriter.CoordinateSystemWkt = sc.CoordinateSystemWkt;
                                scWriter.Description = sc.Description;
                                
                                scWriter.ExtentType = sc.ExtentType;

                                using (var geom = fact.CreateGeometry(sc.ExtentGeometryText))
                                {
                                    byte[] fgf = fact.GetFgf(geom);
                                    scWriter.Extent = fgf;
                                }

                                scWriter.Name = sc.Name;
                                scWriter.XYTolerance = sc.XYTolerance;
                                scWriter.ZTolerance = sc.ZTolerance;

                                scWriter.WriteSpatialContext();
                            }
                        }
                    }

                    

                    //Write logical schema
                    if (this.Schemas != null)
                    {
                        var schemas = CloneSchemas(this.Schemas);

                        schemas.WriteXml(writer);
                    }

                    //Write physical mappings
                    if (this.Mappings != null)
                    {
                        this.Mappings.WriteXml(writer);
                    }

                    writer.Close();
                }
                ws.Close();
            }
        }
 private static IRing FlattenRing(IRing ring, FgfGeometryFactory factory)
 {
     CurveSegmentCollection curves = new CurveSegmentCollection();
     foreach (ICurveSegmentAbstract curve in ring.CurveSegments)
     {
         curves.Add(FlattenCurveSegment(curve, factory));
     }
     return factory.CreateRing(curves);
 }
 public FdoInMemoryProvider()
 {
     _geomFactory = new FgfGeometryFactory();
 }
 public FdoInMemoryProvider()
 {
     _geomFactory = new FgfGeometryFactory();
 }