DirectPositionCollection GetDirectPositions(IPosition[] positions) { DirectPositionCollection dpc = new DirectPositionCollection(); foreach (IPosition p in positions) { IDirectPosition xy = m_Factory.CreatePositionXY(p.X, p.Y); dpc.Add(xy); } return(dpc); }
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)); }
IRing GetRing(Ring r) { CurveSegmentCollection csc = new CurveSegmentCollection(); foreach (IDivider d in r.Edge) { LineGeometry line = d.LineGeometry; ICurveSegmentAbstract cseg = null; if (line is SectionGeometry) { SectionGeometry section = (line as SectionGeometry); line = section.Make(); } if (line is MultiSegmentGeometry) { MultiSegmentGeometry mseg = (line as MultiSegmentGeometry); DirectPositionCollection dpc = GetDirectPositions(mseg.Data); cseg = m_Factory.CreateLineStringSegment(dpc); } else if (line is SegmentGeometry) { SegmentGeometry segment = (line as SegmentGeometry); DirectPositionCollection dpc = GetDirectPositions(new IPosition[] { segment.Start, segment.End }); cseg = m_Factory.CreateLineStringSegment(dpc); } else if (line is ArcGeometry) { ArcGeometry arc = (line as ArcGeometry); IPosition mp = arc.GetMidPosition(); IDirectPosition bc = m_Factory.CreatePositionXY(arc.BC.X, arc.BC.Y); IDirectPosition mid = m_Factory.CreatePositionXY(mp.X, mp.Y); IDirectPosition ec = m_Factory.CreatePositionXY(arc.EC.X, arc.EC.Y); cseg = m_Factory.CreateCircularArcSegment(bc, mid, ec); } else { throw new NotSupportedException("Unknown line type: " + line.GetType().Name); } csc.Add(cseg); } return(m_Factory.CreateRing(csc)); }
void RunExport(string fileName) { CadastralMapModel mapModel = CadastralMapModel.Current; using (ICreateDataStore cmd = m_Connection.CreateCommand(CommandType.CommandType_CreateDataStore) as ICreateDataStore) { try { cmd.DataStoreProperties.SetProperty("File", fileName); cmd.Execute(); } catch (OSGeo.FDO.Common.Exception ex) { Console.WriteLine(ex.Message); } } // The connection after the created is ConnectionState_Closed, so open it! m_Connection.ConnectionInfo.ConnectionProperties.SetProperty("File", fileName); m_Connection.Open(); // Define coordinate system using (ICreateSpatialContext cmd = m_Connection.CreateCommand(CommandType.CommandType_CreateSpatialContext) as ICreateSpatialContext) { ISpatialSystem ss = mapModel.SpatialSystem; cmd.CoordinateSystem = ss.Name; // CSMap key name cmd.ExtentType = SpatialContextExtentType.SpatialContextExtentType_Static; IWindow mapExtent = mapModel.Extent; IDirectPosition minxy = m_Factory.CreatePositionXY(mapExtent.Min.X, mapExtent.Min.Y); IDirectPosition maxxy = m_Factory.CreatePositionXY(mapExtent.Max.X, mapExtent.Max.Y); IEnvelope extent = m_Factory.CreateEnvelope(minxy, maxxy); IGeometry gx = m_Factory.CreateGeometry(extent); cmd.Extent = m_Factory.GetFgf(gx); cmd.XYTolerance = 0.000001; // resolution? cmd.CoordinateSystemWkt = EditingController.Current.GetCoordinateSystemText(); cmd.Execute(); } // Define feature schema FeatureSchema fs = new FeatureSchema("Steve", "This is a test"); FeatureClass fc = new FeatureClass("FC", "Test feature class"); fs.Classes.Add(fc); GeometricPropertyDefinition gp = new GeometricPropertyDefinition("Geometry", "Polygon property"); // When you stick more than one geometric type into the output, you can't // convert to SHP (not with FDO Toolbox anyway). //gp.GeometryTypes = (int)GeometricType.GeometricType_Surface; gp.GeometryTypes = (int)GeometricType.GeometricType_All; fc.Properties.Add(gp); fc.GeometryProperty = gp; // c.f. FdoToolbox ExpressUtility DataPropertyDefinition dp = new DataPropertyDefinition("ID", "Test ID"); dp.DataType = DataType.DataType_Int32; dp.Nullable = false; dp.ReadOnly = true; dp.IsAutoGenerated = true; fc.Properties.Add(dp); // Feature class requires an identity column for the insert fc.IdentityProperties.Add(dp); using (IApplySchema cmd = m_Connection.CreateCommand(CommandType.CommandType_ApplySchema) as IApplySchema) { cmd.FeatureSchema = fs; cmd.Execute(); } mapModel.Index.QueryWindow(null, SpatialType.Polygon | SpatialType.Point, ExportFeature); m_Connection.Flush(); m_Connection.Close(); }
private static IDirectPosition FlattenPosition(IDirectPosition pos, FgfGeometryFactory factory) { return(factory.CreatePositionXY(pos.X, pos.Y)); }
private static IDirectPosition FlattenPosition(IDirectPosition pos, FgfGeometryFactory factory) { return factory.CreatePositionXY(pos.X, pos.Y); }