public void Load(IPersistStream stream) { if (_module == null || _module.MapDocument == null || _module.MapDocument.Maps == null) { return; } string mapName = (string)stream.Load("Name", ""); foreach (IMap map in _module.MapDocument.Maps) { if (map.Name == mapName) { List <ISnapSchema> schemas = _module[map]; schemas.Clear(); while (true) { ISnapSchema schema = stream.Load("SnapSchema", null, new SnapSchema(map)) as ISnapSchema; if (schema == null) { break; } schemas.Add(schema); } break; } } }
public SnapSchemaItem(IMap map, ISnapSchema schema) { _schema = schema; if (_schema == null) { return; } foreach (ISnapLayer sLayer in schema) { if (!(sLayer is SnapLayer)) { continue; } _rows.Add(new SnapLayerRow(sLayer as SnapLayer)); } foreach (IDatasetElement element in map.MapElements) { if (!(element is IFeatureLayer) || HasFeatureLayer(element as IFeatureLayer)) { continue; } SnapLayer sLayer = new SnapLayer(element as IFeatureLayer, SnapMethode.None); _rows.Add(new SnapLayerRow(sLayer)); } }
async void combo_SelectedIndexChanged(object sender, EventArgs e) { if (_combo.SelectedItem is SnapSchemaItem) { _activeSnapSchema = ((SnapSchemaItem)_combo.SelectedItem).SnapSchema; } else { _activeSnapSchema = null; } if (_module != null && _module.MapDocument != null && _module.MapDocument.FocusMap != null && _module.MapDocument.FocusMap.Display != null) { await _module.LoadGeometry( _module.MapDocument.FocusMap, _activeSnapSchema, _module.MapDocument.FocusMap.Display.Envelope); } }
public void Snap(ref double X, ref double Y) { ISnapSchema schema = this.ActiveSnapSchema; if (schema == null) { return; } foreach (ISnapLayer sLayer in schema) { List <IGeometry> geometries; if (!_snapGeometries.TryGetValue(sLayer, out geometries)) { continue; } if (sLayer.FeatureLayer == null || !sLayer.FeatureLayer.Visible) { continue; } double dist = double.MaxValue; IPoint ret = null; foreach (IGeometry geometry in geometries) { if (geometry == null) { continue; } //IEnvelope env = geometry.Envelope; //if (env == null) continue; //if (env.minx > X || env.maxx < X || // env.miny > Y || env.maxy < Y) continue; double distance = -1.0, x = X, y = Y; bool found = false; if (Bit.Has(sLayer.Methode, SnapMethode.Vertex) && SnapVertex(geometry, ref x, ref y, out distance)) { found = true; } else if (Bit.Has(sLayer.Methode, SnapMethode.EndPoint) && SnapEndPoint(geometry, ref x, ref y, out distance)) { found = true; } else if (Bit.Has(sLayer.Methode, SnapMethode.Edge) && SnapEdge(geometry, ref x, ref y, out distance)) { found = true; } if (found && distance < dist) { dist = distance; if (ret == null) { ret = new Point(x, y); } else { ret.X = x; ret.Y = y; } } } if (ret != null) { X = ret.X; Y = ret.Y; } } }
internal void LoadGeometry(IMap map, ISnapSchema schema, IEnvelope envelope) { _snapGeometries.Clear(); IGUIApplication guiApp = (_doc != null) ? _doc.Application as IGUIApplication : null; if (map == null || schema == null || envelope == null || map.Display == null || map.Display.mapScale >= schema.MaxScale) { return; } foreach (ISnapLayer sLayer in schema) { if (sLayer == null || sLayer.FeatureLayer == null || sLayer.FeatureLayer.FeatureClass == null || _doc == null || _doc.FocusMap == null || _doc.FocusMap.Display == null) { continue; } if (sLayer.FeatureLayer.MinimumScale >= 1 && sLayer.FeatureLayer.MinimumScale > _doc.FocusMap.Display.mapScale) { continue; } if (sLayer.FeatureLayer.MaximumScale >= 1 && sLayer.FeatureLayer.MaximumScale < _doc.FocusMap.Display.mapScale) { continue; } SpatialFilter filter = new SpatialFilter(); filter.FeatureSpatialReference = map.Display.SpatialReference; filter.FilterSpatialReference = map.Display.SpatialReference; filter.Geometry = envelope; filter.SpatialRelation = spatialRelation.SpatialRelationIntersects; filter.AddField(sLayer.FeatureLayer.FeatureClass.ShapeFieldName); if (guiApp != null) { guiApp.StatusBar.Text = "Query Snaplayer: " + sLayer.FeatureLayer.Title; guiApp.StatusBar.Refresh(); } List <IGeometry> geometries = new List <IGeometry>(); using (IFeatureCursor cursor = sLayer.FeatureLayer.FeatureClass.GetFeatures(filter)) { IFeature feature; while ((feature = cursor.NextFeature) != null) { if (feature.Shape != null) { geometries.Add(feature.Shape); } } } _snapGeometries.Add(sLayer, geometries); } if (guiApp != null) { guiApp.StatusBar.Text = null; guiApp.StatusBar.Refresh(); } }
public SnapSchemaItem(ISnapSchema schema) { _schema = schema; }