private FdoRow Flatten(FdoRow row) { //Not applicable? if (row.Geometry == null) { return(row); } //Already 2D? Move along! if (FdoGeometryUtil.Is2D(row.Geometry)) { return(row); } IGeometry geom = row.Geometry; IGeometry trans = FdoGeometryUtil.Flatten(geom, _geomFactory); //Dispose the original if flatten returned a new instance if (!IGeometry.ReferenceEquals(geom, trans)) { row.Geometry = trans; geom.Dispose(); } return(row); }
private void btnPreview_Click(object sender, EventArgs e) { try { using (IGeometry fgeom = _geomFactory.CreateGeometry(txtGeometry.Text)) { byte[] wkb = null; if (!FdoGeometryUtil.Is2D(fgeom)) { using (IGeometry ffgeom = FdoGeometryUtil.Flatten(fgeom, _geomFactory)) { wkb = _geomFactory.GetWkb(ffgeom); } } else { wkb = _geomFactory.GetWkb(fgeom); } SharpMap.Geometries.Geometry sgeom = SharpMap.Geometries.Geometry.GeomFromWKB(wkb); _layer.DataSource = new SharpMap.Data.Providers.GeometryProvider(sgeom); SharpMap.Geometries.BoundingBox bbox = _mapCtl.Map.GetExtents(); bbox = bbox.Grow(2.0, 2.0); _mapCtl.Map.ZoomToBox(bbox); _mapCtl.Refresh(); btnOK.Enabled = true; } } catch (Exception) { MessageService.ShowError("The specified text does not constitute a valid geometry"); btnOK.Enabled = false; } }
/// <summary> /// Converts an FDO Geometry to a SharpMap geometry /// </summary> /// <param name="geom">The FDO geometry</param> /// <returns></returns> public static Sm.Geometry FromFdoGeometry(FdoGeometry geom, OSGeo.FDO.Geometry.FgfGeometryFactory geomFactory) { if (FdoGeometryUtil.Is2D(geom.InternalInstance)) { //Get the WKB form of the geometry byte[] wkb = FdoGeometryFactory.Instance.GetWkb(geom.InternalInstance); return(GeometryFromWKB.Parse(wkb)); } else { using (OSGeo.FDO.Geometry.IGeometry flattened = FdoGeometryUtil.Flatten(geom.InternalInstance, geomFactory)) { //Get the WKB form of the geometry byte[] wkb = FdoGeometryFactory.Instance.GetWkb(flattened); return(GeometryFromWKB.Parse(wkb)); } } }