private static bool Relates(Geometry a, SpatialRelationship rel, Geometry b) { if (a == null || b == null) { return(false); } switch (rel) { case SpatialRelationship.EnvelopeIntersects: case SpatialRelationship.IndexIntersects: case SpatialRelationship.Intersects: return(GeometryEngine.Instance.Intersects(a, b)); case SpatialRelationship.Touches: return(GeometryEngine.Instance.Touches(a, b)); case SpatialRelationship.Overlaps: return(GeometryEngine.Instance.Overlaps(a, b)); case SpatialRelationship.Crosses: return(GeometryEngine.Instance.Crosses(a, b)); case SpatialRelationship.Within: return(GeometryEngine.Instance.Within(a, b)); case SpatialRelationship.Contains: return(GeometryEngine.Instance.Contains(a, b)); } return(false); }
public void Examine(GameObject sentByPlayer) { // if distance is too big or is self-examination, send normal examine message if (Vector3.Distance(sentByPlayer.WorldPosServer(), gameObject.WorldPosServer()) >= maxInteractionDistance || sentByPlayer == gameObject) { Chat.AddExamineMsg(sentByPlayer, $"This is <b>{VisibleName}</b>.\n" + $"{Equipment.Examine()}" + $"<color={LILAC_COLOR}>{Health.GetExamineText()}</color>"); return; } // start itemslot observation interactableStorage.ItemStorage.ServerAddObserverPlayer(sentByPlayer); // send message to enable examination window PlayerExaminationMessage.Send(sentByPlayer, this, true); //stop observing when target player is too far away var relationship = RangeRelationship.Between( sentByPlayer, gameObject, maxInteractionDistance, ServerOnObservationEnded ); SpatialRelationship.ServerActivate(relationship); }
private void OnCuffChangeServer(bool wasCuffed, bool nowCuffed) { if (!CanPlayerStillBeObserved()) { SpatialRelationship.ServerEnd(this); } }
private void OnConsciousStateChangeServer(ConsciousState oldState, ConsciousState newState) { if (!CanPlayerStillBeObserved()) { SpatialRelationship.ServerEnd(this); } }
private void UpdatePollCrossMatrixRelationships() { //used in update manager when there is a cross matrix relationship //that this registertile is the leader for. Checks the relationship and switches it //over to same matrix if they both end up on the same matrix if (crossMatrixRelationships != null) { //keeping null to avoid GC unless a switch happens, which should be rare List <BaseSpatialRelationship> toSwitch = null; List <BaseSpatialRelationship> toCancel = null; foreach (var crossMatrixRelationship in crossMatrixRelationships) { var cancelled = crossMatrixRelationship.ShouldRelationshipEnd(); if (cancelled) { if (toCancel == null) { toCancel = new List <BaseSpatialRelationship>(); } toCancel.Add(crossMatrixRelationship); } else { //not cancelled, check if we moved to same matrix if (crossMatrixRelationship.Other(this).Matrix == this.Matrix) { if (toSwitch == null) { toSwitch = new List <BaseSpatialRelationship>(); } toSwitch.Add(crossMatrixRelationship); } } } if (toCancel != null) { foreach (var cancelled in toCancel) { Logger.LogTraceFormat("Cancelling spatial relationship {0} because OnRelationshipChanged" + " returned true.", Category.SpatialRelationship, cancelled); SpatialRelationship.ServerEnd(cancelled); } } if (toSwitch != null) { foreach (var switched in toSwitch) { Logger.LogTraceFormat("Switching spatial relationship {0} to same matrix because" + " objects moved to the same matrix.", Category.SpatialRelationship, switched); RemoveCrossMatrixRelationship(switched); AddSameMatrixRelationship(switched); } } } }
public virtual void OnDespawnServer(DespawnInfo info) { //cancel all relationships if (sameMatrixRelationships != null) { for (int i = sameMatrixRelationships.Count - 1; i >= 0; i--) { var relationship = sameMatrixRelationships[i]; Logger.LogTraceFormat("Cancelling spatial relationship {0} because {1} is despawning.", Category.SpatialRelationship, relationship, this); SpatialRelationship.ServerEnd(relationship); } } if (crossMatrixRelationships != null) { for (int i = crossMatrixRelationships.Count - 1; i >= 0; i--) { var relationship = crossMatrixRelationships[i]; Logger.LogTraceFormat("Cancelling spatial relationship {0} because {1} is despawning.", Category.SpatialRelationship, relationship, this); SpatialRelationship.ServerEnd(relationship); } } OnDespawnedServer.Invoke(); }
internal static bool HasRelationship(IGeometryEngine engine, Geometry geom1, Geometry geom2, SpatialRelationship relationship) { switch (relationship) { case SpatialRelationship.Intersects: return(engine.Intersects(geom1, geom2)); case SpatialRelationship.IndexIntersects: return(engine.Intersects(geom1, geom2)); case SpatialRelationship.EnvelopeIntersects: return(engine.Intersects(geom1.Extent, geom2.Extent)); case SpatialRelationship.Contains: return(engine.Contains(geom1, geom2)); case SpatialRelationship.Crosses: return(engine.Crosses(geom1, geom2)); case SpatialRelationship.Overlaps: return(engine.Overlaps(geom1, geom2)); case SpatialRelationship.Touches: return(engine.Touches(geom1, geom2)); case SpatialRelationship.Within: return(engine.Within(geom1, geom2)); } return(false); //unknown relationship }
public void ServerPerformInteraction(MouseDrop interaction) { if (allowedToInteract == false) { return; } if (interaction.IsFromInventory && interaction.TargetObject == gameObject) { // try to add item to this storage Inventory.ServerTransfer(interaction.FromSlot, itemStorage.GetBestSlotFor(interaction.UsedObject)); } else { // player can observe this storage itemStorage.ServerAddObserverPlayer(interaction.Performer); ObserveInteractableStorageMessage.Send(interaction.Performer, this, true); // if we are observing a storage not in our inventory (such as another player's top // level inventory or a storage within their inventory, or a box/backpack sitting on the ground), we must stop observing when it // becomes unobservable for whatever reason (such as the owner becoming unobservable) var rootStorage = itemStorage.GetRootStorage(); if (interaction.Performer != rootStorage.gameObject) { // stop observing when it becomes unobservable for whatever reason var relationship = ObserveStorageRelationship.Observe(this, interaction.Performer.GetComponent <RegisterPlayer>(), PlayerScript.interactionDistance, ServerOnObservationEnded); SpatialRelationship.ServerActivate(relationship); } } }
/// <summary> /// Finds the features in the map by the specified criteria, grouped by feature class /// </summary> /// <param name="mapView">The map view containing the layers to search</param> /// <param name="searchGeometry">The search geometry</param> /// <param name="spatialRelationship">The spatial relationship between the found features /// and the search geometry.</param> /// <param name="targetSelectionType">The target selection type that determines which layers /// are searched.</param> /// <param name="layerPredicate">An extra layer predicate that allows for a more /// fine-granular determination of the layers to be searched.</param> /// <param name="featurePredicate">An extra feature predicate that allows to determine /// criteria on the feature level.</param> /// <param name="selectedFeatures">The selected features, relevant only for /// <see cref="targetSelectionType"/> with value <see cref="TargetFeatureSelection.SameClass"/>. </param> /// <param name="cancelableProgressor"></param> /// <returns></returns> public static IEnumerable <KeyValuePair <FeatureClass, List <Feature> > > FindFeatures( [NotNull] MapView mapView, [NotNull] ArcGIS.Core.Geometry.Geometry searchGeometry, SpatialRelationship spatialRelationship, TargetFeatureSelection targetSelectionType, [CanBeNull] Predicate <FeatureLayer> layerPredicate, [CanBeNull] Predicate <Feature> featurePredicate, List <Feature> selectedFeatures, CancelableProgressor cancelableProgressor = null) { // NOTE: FeatureLayer.Search is quite useless, as we cannot control recyclability and as soon as the cursor // is disposed, the feature's geometry is wrong! // -> Get the distinct feature classes (TODO: include layer definition queries) IEnumerable <FeatureLayer> featureLayers = GetLayers <FeatureLayer>( mapView, fl => IsLayerApplicable(fl, targetSelectionType, layerPredicate, selectedFeatures)); IEnumerable <IGrouping <IntPtr, FeatureLayer> > layersGroupedByClass = featureLayers.GroupBy(fl => fl.GetFeatureClass().Handle); foreach (var layersInClass in layersGroupedByClass) { // One query per distinct definition query, then make OIDs distinct FeatureClass featureClass = null; List <Feature> features = new List <Feature>(); foreach (IGrouping <string, FeatureLayer> layers in layersInClass.GroupBy( fl => fl.DefinitionQuery)) { if (cancelableProgressor != null && cancelableProgressor.CancellationToken.IsCancellationRequested) { yield break; } featureClass = layers.First().GetFeatureClass(); QueryFilter filter = GdbQueryUtils.CreateSpatialFilter(searchGeometry, spatialRelationship); filter.WhereClause = layers.Key; IEnumerable <Feature> foundFeatures = GdbQueryUtils .GetFeatures(featureClass, filter, false) .Where(f => featurePredicate == null || featurePredicate(f)); features.AddRange(foundFeatures); } if (featureClass != null && features.Count > 0) { yield return(new KeyValuePair <FeatureClass, List <Feature> >( featureClass, features.DistinctBy(f => f.GetObjectID()).ToList())); } } }
private void CheckSameMatrixRelationships() { //fires hooks for these relationships and checks if they should be switched to cross-matrix if (sameMatrixRelationships != null) { //keeping null to avoid GC unless a switch happens, which should be rare List <BaseSpatialRelationship> toSwitch = null; List <BaseSpatialRelationship> toCancel = null; foreach (var sameMatrixRelationship in sameMatrixRelationships) { var cancelled = sameMatrixRelationship.ShouldRelationshipEnd(); if (cancelled) { if (toCancel == null) { toCancel = new List <BaseSpatialRelationship>(); } toCancel.Add(sameMatrixRelationship); } else { //not cancelled, check if we moved cross-matrix if (sameMatrixRelationship.Other(this).Matrix != this.Matrix) { if (toSwitch == null) { toSwitch = new List <BaseSpatialRelationship>(); } toSwitch.Add(sameMatrixRelationship); } } } if (toCancel != null) { foreach (var cancelled in toCancel) { Logger.LogTraceFormat("Cancelling spatial relationship {0} because OnRelationshipChanged" + " returned true.", Category.SpatialRelationship, cancelled); SpatialRelationship.ServerEnd(cancelled); } } if (toSwitch != null) { foreach (var switched in toSwitch) { Logger.LogTraceFormat("Switching spatial relationship {0} to cross matrix because" + " objects moved to different matrices.", Category.SpatialRelationship, switched); RemoveSameMatrixRelationship(switched); AddCrossMatrixRelationship(switched); } } } }
public SelectionSettings( SketchGeometryType sketchGeometryType = SketchGeometryType.Rectangle, int selectionTolerancePixels = 3, SpatialRelationship spatialRelationship = SpatialRelationship.Intersects) { SketchGeometryType = sketchGeometryType; SketchOutputMode = SketchOutputMode.Map; SelectionTolerancePixels = selectionTolerancePixels; SpatialRelationship = spatialRelationship; }
public static SpatialQueryFilter CreateSpatialFilter( [NotNull] ArcGIS.Core.Geometry.Geometry filterGeometry, SpatialRelationship spatialRelationship = SpatialRelationship.Intersects, SearchOrder searchOrder = SearchOrder.Spatial) { Assert.ArgumentNotNull(filterGeometry, nameof(filterGeometry)); return(new SpatialQueryFilter { FilterGeometry = filterGeometry, SpatialRelationship = spatialRelationship, SearchOrder = searchOrder }); }
public void Examine(GameObject sentByPlayer) { if (sentByPlayer.TryGetComponent <PlayerScript>(out var sentByPlayerScript) == false) { return; } if (sentByPlayerScript.PlayerState != PlayerScript.PlayerStates.Ghost) { // if distance is too big or is self-examination, send normal examine message if (Vector3.Distance(sentByPlayer.WorldPosServer(), gameObject.WorldPosServer()) >= maxInteractionDistance || sentByPlayer == gameObject) { BasicExamine(sentByPlayer); return; } } //If youre not normal or ghost then only allow basic examination //TODO maybe in future have this be a separate setting for each player type? if (sentByPlayerScript.PlayerState != PlayerScript.PlayerStates.Normal && sentByPlayerScript.PlayerState != PlayerScript.PlayerStates.Ghost) { BasicExamine(sentByPlayer); return; } // start itemslot observation this.GetComponent <DynamicItemStorage>().ServerAddObserverPlayer(sentByPlayer); // send message to enable examination window PlayerExaminationMessage.Send(sentByPlayer, this, true); //Allow ghosts to keep the screen open even if player moves away if (sentByPlayerScript.PlayerState == PlayerScript.PlayerStates.Ghost) { return; } //stop observing when target player is too far away var relationship = RangeRelationship.Between( sentByPlayer, gameObject, maxInteractionDistance, ServerOnObservationEnded ); SpatialRelationship.ServerActivate(relationship); }
/// <summary> /// Performs a spatial query against a feature class /// </summary> /// <remarks>It is assumed that the feature layer and the search geometry are using the same spatial reference.</remarks> /// <param name="searchFC">The feature class to be searched.</param> /// <param name="searchGeometry">The geometry used to perform the spatial query.</param> /// <param name="spatialRelationship">The spatial relationship used by the spatial filter.</param> /// <param name="useRecyclingCursor"></param> /// <returns>Cursor containing the features that satisfy the spatial search criteria.</returns> public static RowCursor Search(this Table searchFC, Geometry searchGeometry, SpatialRelationship spatialRelationship, bool useRecyclingCursor) { RowCursor rowCursor = null; // define a spatial query filter var spatialQueryFilter = new SpatialQueryFilter { // passing the search geometry to the spatial filter FilterGeometry = searchGeometry, // define the spatial relationship between search geometry and feature class SpatialRelationship = spatialRelationship }; // apply the spatial filter to the feature layer in question rowCursor = searchFC.Search(spatialQueryFilter, useRecyclingCursor); return(rowCursor); }
private bool SelectTargets(List <Feature> selectedFeatures, Geometry sketch, CancelableProgressor progressor) { const TargetFeatureSelection targetFeatureSelection = TargetFeatureSelection.VisibleFeatures; sketch = ToolUtils.SketchToSearchGeometry(sketch, GetSelectionTolerancePixels(), out bool _); Predicate <Feature> canUseAsTargetFeature = t => CanUseAsTargetFeature(selectedFeatures, t); SpatialRelationship spatialRel = SketchType == SketchGeometryType.Polygon ? SpatialRelationship.Contains : SpatialRelationship.Intersects; var foundOidsByLayer = MapUtils.FindFeatures(ActiveMapView, sketch, spatialRel, targetFeatureSelection, CanUseAsTargetLayer, canUseAsTargetFeature, selectedFeatures, progressor); // TODO: Picker if single click and several found if (progressor != null && progressor.CancellationToken.IsCancellationRequested) { _msg.Warn("Calculation of reshape lines was cancelled."); return(false); } IList <Feature> allTargetFeatures = GetDistinctSelectedFeatures(foundOidsByLayer, _changeAlongCurves?.TargetFeatures, KeyboardUtils.IsModifierPressed(Keys.Shift)); _changeAlongCurves = allTargetFeatures.Count > 0 ? CalculateReshapeCurves(selectedFeatures, allTargetFeatures, progressor) : new ChangeAlongCurves(new List <CutSubcurve>(), ReshapeAlongCurveUsability.NoTarget); _feedback.Update(_changeAlongCurves); return(true); }
public void Examine(GameObject SentByPlayer) { // if player is not inspecting self and distance is not too big if (SentByPlayer != gameObject && Vector3.Distance(SentByPlayer.WorldPosServer(), gameObject.WorldPosServer()) <= maxInteractionDistance) { // start itemslot observation interactableStorage.ItemStorage.ServerAddObserverPlayer(SentByPlayer); // send message to enable examination window PlayerExaminationMessage.Send(SentByPlayer, this, true); //stop observing when target player is too far away var relationship = RangeRelationship.Between( SentByPlayer, gameObject, maxInteractionDistance, ServerOnObservationEndedd ); SpatialRelationship.ServerActivate(relationship); } }
public void ServerPerformInteraction(MouseDrop interaction) { if (interaction.IsFromInventory && interaction.TargetObject == gameObject) { //try to add item to this storage Inventory.ServerTransfer(interaction.FromSlot, itemStorage.GetBestSlotFor(interaction.UsedObject)); } else { //player can observe this storage itemStorage.ServerAddObserverPlayer(interaction.Performer); ObserveInteractableStorageMessage.Send(interaction.Performer, this, true); if (!interaction.IsFromInventory) { SpatialRelationship.ServerActivate(RangeRelationship.Between(interaction.Performer, interaction.UsedObject, PlayerScript.interactionDistance, ServerOnRelationshipEnded)); } } }
/// <summary> /// Returns oids of features filtered by spatial relationship. Honors definition queries on the layer. /// </summary> public static IEnumerable <long> FilterLayerOidsByGeometry( BasicFeatureLayer layer, ArcGIS.Core.Geometry.Geometry filterGeometry, SpatialRelationship spatialRelationship = SpatialRelationship.Intersects) { var qf = new SpatialQueryFilter() { FilterGeometry = filterGeometry, SpatialRelationship = spatialRelationship }; var oids = new List <long>(); using (RowCursor rowCursor = layer.Search(qf)) { while (rowCursor.MoveNext()) { oids.Add(rowCursor.Current.GetObjectID()); } } return(oids); }
/// <summary> /// Returns features filtered by spatial relationship. Honors definition queries on the layer. /// </summary> public static IEnumerable <Feature> FilterLayerFeaturesByGeometry( BasicFeatureLayer layer, ArcGIS.Core.Geometry.Geometry filterGeometry, SpatialRelationship spatialRelationship = SpatialRelationship.Intersects) { var qf = new SpatialQueryFilter() { FilterGeometry = filterGeometry, SpatialRelationship = spatialRelationship }; var features = new List <Feature>(); using (RowCursor rowCursor = layer.Search(qf)) { while (rowCursor.MoveNext()) { features.Add((Feature)rowCursor.Current); } } return(features); }
private Dictionary <BasicFeatureLayer, List <long> > FindFeaturesOfAllLayers( Geometry selectionGeometry, SpatialRelationship spatialRelationship) { var featuresPerLayer = new Dictionary <BasicFeatureLayer, List <long> >(); foreach (BasicFeatureLayer layer in MapView.Active.Map.GetLayersAsFlattenedList().OfType <BasicFeatureLayer>()) { if (CanSelectFromLayer(layer)) { IEnumerable <long> oids = MapUtils.FilterLayerOidsByGeometry(layer, selectionGeometry, spatialRelationship); if (oids.Any()) { featuresPerLayer.Add(layer, oids.ToList()); } } } return(featuresPerLayer); }
/// <summary> /// </summary> /// <param name="writer"></param> /// <param name="spatial"></param> /// <param name="parentCursor"></param> private void ExportSpatialRelatedObjects(XmlWriter writer, SpatialRelationship spatial, IFeatureCursor parentCursor) { IFeatureLayer featureLayerFromDatasetName = GetFeatureLayerFromDatasetName(spatial.ObjectClass.name); if (featureLayerFromDatasetName == null) return; var enum2 = (esriSpatialRelEnum) Enum.Parse(typeof(esriSpatialRelEnum), spatial.RelationshipType); StartExportObjectClass(writer, spatial.ObjectClass, featureLayerFromDatasetName as IDisplayTable); for (IFeature feature = parentCursor.NextFeature(); feature != null; feature = parentCursor.NextFeature()) { ISpatialFilter filter = new SpatialFilterClass { Geometry = feature.Shape, SpatialRel = enum2 }; IFeatureCursor cursor = featureLayerFromDatasetName.FeatureClass.Search(filter, true); ExportObjectClass(writer, spatial.ObjectClass, cursor as ICursor, featureLayerFromDatasetName as IDisplayTable); } EndExportObjectClass(writer); }
public Dictionary <int, List <int> > GetZone() { Dictionary <int, List <int> > dic = new Dictionary <int, List <int> >(); var fs_centroid = ProjectService.Project.CentroidLayer.FeatureSet; var fs = FeatureLayer.DataSet as IFeatureSet; var dt = fs.DataTable; var npolygon = fs.NumRows(); var npt = fs_centroid.NumRows(); var polygon = new List <IFeature>(); var list_id = new List <int>(); for (int i = 0; i < npolygon; i++) { var id = int.Parse(dt.Rows[i][ZoneField].ToString()); var pts = new List <int>(); dic.Add(id, pts); var py = fs.GetFeature(i); polygon.Add(py); list_id.Add(id); } for (int i = 0; i < npt; i++) { var geo_pt = fs_centroid.GetFeature(i).Geometry; int t = 0; foreach (var fea in polygon) { if (SpatialRelationship.PointInPolygon(fea.Geometry.Coordinates, geo_pt.Coordinates[0])) { dic[list_id[t]].Add(i); break; } t++; } } return(dic); }
public override void Map() { int progress = 0; OnProcessing(progress); int count = 1; if (Source is IFeatureSet) { try { var fea_target = TargetFeatureSet.Features; var fea_source = (Source as FeatureSet); int nfea_target = fea_target.Count; int[] target_index = new int[nfea_target]; DataTable dt_source = fea_source.DataTable; int index_ap = 0; for (int i = 0; i < nfea_target; i++) { target_index[i] = -1; int j = 0; foreach (var fea in fea_source.Features) { if (SpatialRelationship.PointInPolygon(fea.Geometry.Coordinates, fea_target[i].Geometry.Coordinates[0])) { target_index[i] = j; break; } j++; } progress = i * 100 / nfea_target; OnProcessing(progress); } OnProcessing(0); foreach (var ap in ArealProperties) { var vv = Package.GetType().GetProperty(ap.PropertyName).GetValue(Package); if (vv != null) { if (ap.TypeName == typeof(float).FullName) { var fl = vv as DataCube <float>; if (fl[GridLayer] != null) { for (int i = 0; i < nfea_target; i++) { if (target_index[i] >= 0) { fl[GridLayer, 0, i] = float.Parse(GetValue(ap.AliasName, target_index[i])); } else { fl[GridLayer, 0, i] = (float)ap.DefaultValue; } } } } else if (ap.TypeName == typeof(short).FullName) { var fl = vv as DataCube <short>; if (fl[GridLayer] != null) { for (int i = 0; i < nfea_target; i++) { if (target_index[i] >= 0) { fl[GridLayer, 0, i] = short.Parse(GetValue(ap.AliasName, target_index[i])); } else { fl[GridLayer, 0, i] = (short)ap.DefaultValue; } } } } } progress = index_ap * 100 / ArealProperties.Count; if (progress > count) { OnProcessing(progress); count++; } index_ap++; } OnProcessing(100); OnProcessed(ConstantWords.Successful); } catch (Exception ex) { OnProcessing(100); OnProcessed("Failed. Error message: " + ex.Message); } } }
public IGrid Generate() { if (Source == null) { Source = new RegularGrid(); } if (Domain != null) { Source.Origin = this.Origin; Source.ActualLayerCount = this.LayerCount; Source.RowCount = RowCount; Source.ColumnCount = ColumnCount; Source.IBound = new DataCube <float>(this.LayerCount, RowCount, ColumnCount); Source.DELC = new DataCube <float>(1, 1, RowCount); Source.DELR = new DataCube <float>(1, 1, ColumnCount); Source.DELC.Flags[0, 0] = TimeVarientFlag.Constant; Source.DELR.Flags[0, 0] = TimeVarientFlag.Constant; Source.DELC.Constants[0, 0] = this.XSize; Source.DELR.Constants[0, 0] = this.YSize; Source.DELC.ILArrays[0]["0", ":"] = this.XSize; Source.DELR.ILArrays[0]["0", ":"] = this.YSize; Source.Projection = Domain.Projection; Source.BBox = new Envelope(Domain.Extent.MinX, Domain.Extent.MaxX, Domain.Extent.MinY, Domain.Extent.MaxY); int active = 0; var geo = Domain.Features[0].Geometry.Coordinates; List <Coordinate> centroids = new List <Coordinate>(); for (int r = 0; r < RowCount; r++) { for (int c = 0; c < ColumnCount; c++) { var cor = Source.LocateCentroid(c + 1, r + 1); if (SpatialRelationship.PointInPolygon(geo, cor)) { for (int l = 0; l < Source.ActualLayerCount; l++) { Source.IBound[l, r, c] = 1; } active++; centroids.Add(cor); } } } Source.ActiveCellCount = active; Source.Elevations = new DataCube <float>(Source.LayerCount, 1, active); Source.Elevations.Variables[0] = "Top Elevation"; for (int i = 0; i < active; i++) { //var cell = DEM.ProjToCell(centroids[i]); //if (cell != null && cell.Row > 0) // Source.Elevations.Value[0][0][i] = (float)DEM.Value[cell.Row, cell.Column]; //else // Source.Elevations.Value[0][0][i] = 0; var pt = new Coordinate(centroids[i].X - 0.5 * XSize, centroids[i].Y - 0.5 * YSize); Source.Elevations[0, 0, i] = ZonalStatastics.GetCellAverage(DEM, pt, XSize, AveragingMethod); } for (int l = 1; l < Source.LayerCount; l++) { Source.Elevations.Variables[l] = string.Format("Layer {0} Bottom Elevation", l); for (int i = 0; i < active; i++) { Source.Elevations[l, 0, i] = (float)(Source.Elevations[l - 1, 0, i] - LayerGroups[l - 1].LayerHeight); } } Source.BuildTopology(); Source.Elevations.Topology = Source.Topology; } else { Error = "The domain featureset is null"; } return(Source); }
/// <summary> /// Performs a spatial query against the table/feature class. /// </summary> /// <remarks>It is assumed that the feature class and the search geometry are using the same spatial reference.</remarks> /// <param name="searchTable">The table/feature class to be searched.</param> /// <param name="searchGeometry">The geometry used to perform the spatial query.</param> /// <param name="spatialRelationship">The spatial relationship used by the spatial filter.</param> /// <returns></returns> public static async Task <RowCursor> SearchAsync(this Table searchTable, Geometry searchGeometry, SpatialRelationship spatialRelationship) { RowCursor rowCursor = null; await QueuingTaskFactory.StartNew(() => { // define a spatial query filter var spatialQueryFilter = new SpatialQueryFilter { // passing the search geometry to the spatial filter FilterGeometry = searchGeometry, // define the spatial relationship between search geometry and feature class SpatialRelationship = spatialRelationship }; // apply the spatial filter to the feature class in question rowCursor = searchTable.Search(spatialQueryFilter); }); return(rowCursor); }
/// <summary> /// Performs a spatial query against the table/feature class. /// </summary> /// <remarks>It is assumed that the feature class and the search geometry are using the same spatial reference.</remarks> /// <param name="searchTable">The table/feature class to be searched.</param> /// <param name="searchGeometry">The geometry used to perform the spatial query.</param> /// <param name="spatialRelationship">The spatial relationship used by the spatial filter.</param> /// <returns></returns> public static async Task <RowCursor> SearchAsync(this Table searchTable, Geometry searchGeometry, SpatialRelationship spatialRelationship) { RowCursor rowCursor = null; await QueuingTaskFactory.StartNew(() => { // TODO // define a spatial query filter using the provided spatial relationship and search geometry SpatialQueryFilter spatialQueryFilter = new SpatialQueryFilter(); // apply the spatial filter to the feature class in question rowCursor = searchTable.Search(spatialQueryFilter); }); return(rowCursor); }
private async Task <bool> OnSelectionSketchComplete(Geometry sketchGeometry, CancelableProgressor progressor) { // TODO: Add Utils method to KeyboardUtils to do it in the WPF way SelectionCombinationMethod selectionMethod = KeyboardUtils.IsModifierPressed(Keys.Shift) ? SelectionCombinationMethod.XOR : SelectionCombinationMethod.New; // Polygon-selection allows for more accurate selection in feature-dense areas using contains SpatialRelationship spatialRelationship = SketchType == SketchGeometryType.Polygon ? SpatialRelationship.Contains : SpatialRelationship.Intersects; Geometry selectionGeometry; var pickerWindowLocation = new Point(0, 0); Dictionary <BasicFeatureLayer, List <long> > candidatesOfManyLayers = await QueuedTaskUtils.Run(() => { DisposeOverlays(); selectionGeometry = GetSelectionGeometry(sketchGeometry); pickerWindowLocation = MapView.Active.MapToScreen(selectionGeometry.Extent.Center); // find all features spatially related with selectionGeometry return(FindFeaturesOfAllLayers(selectionGeometry, spatialRelationship)); }); if (!candidatesOfManyLayers.Any()) { if (selectionMethod != SelectionCombinationMethod.XOR) { //no candidate (user clicked into empty space): clear selection await QueuedTask.Run( () => { SelectionUtils.ClearSelection(ActiveMapView.Map); }); return(false); } return(false); } if (SketchingMoveType == SketchingMoveType.Click) { //note if necessary add a virtual core method here for overriding if (GetSelectionSketchMode() == SelectionMode.Original) //alt was pressed: select all xy { await QueuedTask.Run(() => { Selector.SelectLayersFeaturesByOids( candidatesOfManyLayers, selectionMethod); }); } // select a single feature using feature reduction and picker else { IEnumerable <KeyValuePair <BasicFeatureLayer, List <long> > > candidatesOfLayers = await QueuedTask.Run( () => GeometryReducer.GetReducedset(candidatesOfManyLayers)); // show picker if more than one candidate if (GeometryReducer.ContainsManyFeatures(candidatesOfManyLayers)) { List <IPickableItem> pickables = new List <IPickableItem>(); foreach (var layerCandidates in candidatesOfLayers) { pickables.AddRange( await QueuedTask.Run( () => PickerUI.Picker.CreatePickableFeatureItems( layerCandidates))); } var picker = new PickerUI.Picker(pickables, pickerWindowLocation); var item = await picker.PickSingle() as PickableFeatureItem; if (item != null) { var kvp = new KeyValuePair <BasicFeatureLayer, List <long> >( item.Layer, new List <long> { item.Oid }); await QueuedTask.Run(() => { Selector.SelectLayersFeaturesByOids( kvp, selectionMethod); }); } } else { await QueuedTask.Run(() => { Selector.SelectLayersFeaturesByOids( candidatesOfLayers.First(), selectionMethod); }); } } } if (SketchingMoveType == SketchingMoveType.Drag) { //CTRL was pressed: picker shows FC's to select from if (GetSelectionSketchMode() == SelectionMode.UserSelect) { List <IPickableItem> pickingCandidates = await QueuedTask.Run( () => PickableItemAdapter.Get(GetFcCandidates(candidatesOfManyLayers))); var picker = new PickerUI.Picker(pickingCandidates, pickerWindowLocation); var item = await picker.PickSingle() as PickableFeatureClassItem; if (item != null) { await QueuedTask.Run(() => { item.BelongingFeatureLayers.ForEach(layer => { List <long> oids = candidatesOfManyLayers[layer]; SelectionUtils.SelectFeatures(layer, selectionMethod, oids); }); }); } } //no modifier pressed: select all in envelope else { await QueuedTask.Run(() => { Selector.SelectLayersFeaturesByOids( candidatesOfManyLayers, selectionMethod); }); } } MapView activeMapView = MapView.Active; await QueuedTask.Run(() => ProcessSelection(activeMapView, progressor)); return(true); }
/// <summary> /// Performs a spatial query against the table/feature class. /// </summary> /// <remarks>It is assumed that the feature class and the search geometry are using the same spatial reference.</remarks> /// <param name="searchTable">The table/feature class to be searched.</param> /// <param name="searchGeometry">The geometry used to perform the spatial query.</param> /// <param name="spatialRelationship">The spatial relationship used by the spatial filter.</param> /// <returns></returns> public static RowCursor Search(this Table searchTable, Geometry searchGeometry, SpatialRelationship spatialRelationship) { // define a spatial query filter ArcGIS.Core.Data.SpatialQueryFilter spatialQueryFilter = new ArcGIS.Core.Data.SpatialQueryFilter(); // pasing the search geometry to the spatial filter spatialQueryFilter.FilterGeometry = searchGeometry; // define the spatial relationship between search geometry and feature class spatialQueryFilter.SpatialRelationship = spatialRelationship; // apply the spatial filter to the feature class in question return(searchTable.Search(spatialQueryFilter)); }
/// <summary> /// Performs a spatial query against a feature layer. /// </summary> /// <remarks>It is assumed that the feature layer and the search geometry are using the same spatial reference.</remarks> /// <param name="searchTable">The feature layer to be searched.</param> /// <param name="searchGeometry">The geometry used to perform the spatial query.</param> /// <param name="spatialRelationship">The spatial relationship used by the spatial filter.</param> /// <returns>Cursor containing the features that satisfy the spatial search criteria.</returns> public static RowCursor Search(this BasicFeatureLayer searchLayer, Geometry searchGeometry, SpatialRelationship spatialRelationship) { RowCursor rowCursor = null; // define a spatial query filter var spatialQueryFilter = new SpatialQueryFilter { // passing the search geometry to the spatial filter FilterGeometry = searchGeometry, // define the spatial relationship between search geometry and feature class SpatialRelationship = spatialRelationship }; // apply the spatial filter to the feature layer in question rowCursor = searchLayer.Search(spatialQueryFilter); return rowCursor; }
public override bool Execute(ICancelProgressHandler cancelProgressHandler) { var shell = MyAppManager.Instance.CompositionContainer.GetExportedValue <IShellService>(); var prj = MyAppManager.Instance.CompositionContainer.GetExportedValue <IProjectService>(); var model = prj.Project.Model; int progress = 0; int count = 1; Modflow mf = null; if (model is HeiflowModel) { mf = (model as HeiflowModel).ModflowModel; } else if (model is Modflow) { mf = model as Modflow; } if (mf != null) { if (!mf.Packages.ContainsKey(FHBPackage.PackageName)) { var fhb = mf.Select(FHBPackage.PackageName); mf.Add(fhb); } var pck = mf.GetPackage(FHBPackage.PackageName) as FHBPackage; pck.NBDTIM = 2; pck.NHED = 0; pck.IFHBSS = 1; pck.BDTIM = new int[] { 0, prj.Project.Model.TimeService.NumTimeStep }; List <FlowBound> list = new List <FlowBound>(); int npt = _sourcefs.Features.Count; for (int i = 0; i < npt; i++) { var pt = _sourcefs.Features[i].Geometry.Coordinate; int layer = 1; float rate = 0; if (!string.IsNullOrEmpty(LayerField)) { int.TryParse(_sourcefs.DataTable.Rows[i][LayerField].ToString(), out layer); } if (!string.IsNullOrEmpty(FluxRateField)) { float.TryParse(_sourcefs.DataTable.Rows[i][FluxRateField].ToString(), out rate); } for (int j = 0; j < _grid_layer.Features.Count; j++) { var cell = _grid_layer.Features[j].Geometry.Coordinates; if (SpatialRelationship.PointInPolygon(cell, pt)) { FlowBound bound = new FlowBound() { Layer = layer, FlowRate = rate, Row = int.Parse(_grid_layer.DataTable.Rows[j]["ROW"].ToString()), Col = int.Parse(_grid_layer.DataTable.Rows[j]["COLUMN"].ToString()), }; list.Add(bound); break; } } progress = i * 100 / npt; if (progress > count) { cancelProgressHandler.Progress("Package_Tool", progress, "Processing point: " + i); count++; } } if (list.Count > 0) { pck.NFLW = list.Count; var FlowRate = new DataCube <float>(4 + pck.NBDTIM, 1, pck.NFLW) { Name = "FHB_FlowRate", TimeBrowsable = false, AllowTableEdit = true }; FlowRate.Variables[0] = "Layer";//Layer Row Column IAUX FLWRAT(NBDTIM) FlowRate.Variables[1] = "Row"; FlowRate.Variables[2] = "Column"; FlowRate.Variables[3] = "IAUX"; for (int i = 0; i < pck.NBDTIM; i++) { FlowRate.Variables[4 + i] = "FLWRAT " + (i + 1); } for (int i = 0; i < pck.NFLW; i++) { var bound = list[i]; FlowRate[0, 0, i] = bound.Layer; FlowRate[1, 0, i] = bound.Row; FlowRate[2, 0, i] = bound.Col; FlowRate[3, 0, i] = 0; for (int j = 0; j < pck.NBDTIM; j++) { FlowRate[4 + j, 0, i] = bound.FlowRate; } } FlowRate.TimeBrowsable = false; pck.FlowRate = FlowRate; pck.CreateFeature(shell.MapAppManager.Map.Projection, prj.Project.GeoSpatialDirectory); pck.BuildTopology(); pck.IsDirty = true; pck.Save(null); pck.ChangeState(Models.Generic.ModelObjectState.Ready); } else { pck.ChangeState(Models.Generic.ModelObjectState.Standby); cancelProgressHandler.Progress("Package_Tool", 100, "Warning: no points located in the modeling domain."); } return(true); } else { cancelProgressHandler.Progress("Package_Tool", 100, "Error message: Modflow is used by this tool."); return(false); } }