public IGraphEdge GetGraphEdge(IPoint point, double tolerance) { if (point == null) { return(null); } SpatialFilter filter = new SpatialFilter(); filter.Geometry = new Envelope(point.X - tolerance, point.Y - tolerance, point.X + tolerance, point.Y + tolerance); filter.AddField("FDB_SHAPE"); filter.AddField("FDB_OID"); using (IFeatureCursor cursor = GetEdgeFeatures(filter)) { IFeature feature, selected = null; double selectedDist = double.MaxValue; int selectedFcId = int.MinValue; IPoint snappedPoint = null; while ((feature = cursor.NextFeature) != null) { if (!(feature.Shape is IPolyline) || feature.FindField("NETWORK#FCID") == null) { continue; } int fcid = (int)feature["NETWORK#FCID"]; double dist, stat; IPoint spoint = gView.Framework.SpatialAlgorithms.Algorithm.Point2PolylineDistance((IPolyline)feature.Shape, point, out dist, out stat); if (spoint == null) { continue; } if (selected == null || dist <= selectedDist) { if (fcid != -1) { #region Do complex Edge exists IFeatureClass complexEdgeFc = _edgeFcs[-1]; if (complexEdgeFc != null) { QueryFilter complexEdgeFilter = new QueryFilter(); complexEdgeFilter.WhereClause = "fcid=" + fcid + " AND oid=" + feature.OID; complexEdgeFilter.AddField("FDB_OID"); using (IFeatureCursor complexEdgeCursor = complexEdgeFc.GetFeatures(complexEdgeFilter)) { if (complexEdgeCursor.NextFeature != null) { continue; } } } #endregion } selected = feature; selectedDist = dist; selectedFcId = fcid; snappedPoint = spoint; } } if (selected == null) { return(null); } int eid = -1; if (selectedFcId == -1) { #region Complex Edge object eidObj = _fdb._conn.QuerySingleField("SELECT eid FROM " + _fdb.TableName("FC_" + _name + "_ComplexEdges") + " WHERE " + _fdb.DbColName("FDB_OID") + "=" + selected.OID, "eid"); if (eidObj != null) { eid = (int)eidObj; } #endregion } else { object eidObj = _fdb._conn.QuerySingleField("SELECT eid FROM " + _fdb.TableName(_name + "_EdgeIndex") + " WHERE fcid=" + selectedFcId + " AND oid=" + selected.OID, "eid"); if (eidObj != null) { eid = (int)eidObj; } } if (eid != -1) { point.X = snappedPoint.X; point.Y = snappedPoint.Y; IGraphTableAdapter gt = this.GraphTableAdapter(); return(gt.QueryEdge(eid)); } return(null); } }
public pgNetworkFeatureClass(pgFDB fdb, IDataset dataset, string name, GeometryDef geomDef) { _fdb = fdb; _fcid = _fdb.FeatureClassID(_fdb.DatasetID(dataset.DatasetName), name); _dataset = dataset; _geomDef = (geomDef != null) ? geomDef : new GeometryDef(); if (_geomDef != null && _geomDef.SpatialReference == null && dataset is IFeatureDataset) { _geomDef.SpatialReference = ((IFeatureDataset)dataset).SpatialReference; } _fields = new Fields(); _name = _aliasname = name; IDatasetElement element = _dataset[_name + "_Nodes"]; if (element != null) { _nodeFc = element.Class as IFeatureClass; } element = _dataset[_name + "_ComplexEdges"]; if (element != null && element.Class is IFeatureClass) { _edgeFcs.Add(-1, (IFeatureClass)element.Class); } DataTable tab = _fdb.Select("\"FCID\"", "\"FDB_NetworkClasses\"", "\"NetworkId\"=" + _fcid); if (tab != null && tab.Rows.Count > 0) { StringBuilder where = new StringBuilder(); where.Append("\"GeometryType\"=" + ((int)geometryType.Polyline).ToString() + " AND \"ID\" in("); for (int i = 0; i < tab.Rows.Count; i++) { if (i > 0) { where.Append(","); } where.Append(tab.Rows[i]["fcid"].ToString()); } where.Append(")"); tab = _fdb.Select("\"ID\",\"Name\"", "\"FDB_FeatureClasses\"", where.ToString()); if (tab != null) { foreach (DataRow row in tab.Rows) { element = _dataset[row["name"].ToString()]; if (element != null && element.Class is IFeatureClass) { _edgeFcs.Add((int)row["id"], element.Class as IFeatureClass); } } } } _weights = _fdb.GraphWeights(name); Dictionary <Guid, string> weightTableNames = null; Dictionary <Guid, GraphWeightDataType> weightDataTypes = null; if (_weights != null && _weights.Count > 0) { weightTableNames = new Dictionary <Guid, string>(); weightDataTypes = new Dictionary <Guid, GraphWeightDataType>(); foreach (IGraphWeight weight in _weights) { if (weight == null) { continue; } weightTableNames.Add(weight.Guid, _fdb.TableName(_name + "_Weights_" + weight.Guid.ToString("N").ToLower())); weightDataTypes.Add(weight.Guid, weight.DataType); } } _pageManager = new NetworkObjectSerializer.PageManager( gView.Framework.Db.DataProvider.PostgresProvider, _fdb.ConnectionString, _name, _fdb.TableName("FC_" + _name), _fdb.TableName(_name + "_Edges"), _fdb.TableName("FC_" + name + "_Nodes"), weightTableNames, weightDataTypes, _fdb ); }