Пример #1
0
 /// <summary>
 /// Place curve on feature layer
 /// </summary>
 /// <param name="operation"></param>
 /// <param name="curve"></param>
 private static void showCurve(EditOperation operation, Curve curve, Point3d origin)
 {
     try
     {
         // TODO: come up with way of determining whether to make a curve
         // into a polyline or polygon depending on context/user preferences
         // var layer = getFeatureLayer(FeatureLayerType.GH_Preview_Polyline);
         var layer = getFeatureLayer(FeatureLayerType.GH_Preview_Polygon);
         if (layer == null)
         {
             return;
         }
         var projection = layer.GetSpatialReference();
         var ptList     = RhinoUtil.getPointsFromCurves(new List <Curve>()
         {
             curve
         });
         var gisPts   = ptList.Select(p => RhinoUtil.ptToGis(p, origin)).ToList();
         var polyline = new PolygonBuilder(gisPts).ToGeometry();
         // var polyline = PolylineBuilder.CreatePolyline(gisPts, projection);
         operation.Create(layer, polyline);
         operation.ExecuteAsync();
     }
     catch
     {
     }
 }
Пример #2
0
        /// <summary>
        /// Copy selected GIS features into Rhino; assign objects to corresponding layers, and apply attribute values as user text
        /// </summary>
        /// <param name="rhinoDoc">Active Rhino Doc</param>
        internal static void copySelectedObjects(RhinoDoc rhinoDoc)
        {
            if (rhinoDoc == null)
            {
                return;
            }
            var origin = RhinoUtil.getOrigin(rhinoDoc);
            // System.Windows.MessageBox.Show($"Origin {origin.ToString()}");
            var layers = MapView.Active.Map.GetLayersAsFlattenedList().OfType <FeatureLayer>().ToList();

            foreach (var layer in layers)
            {
                var t = QueuedTask.Run(() =>
                {
                    var selectionfromMap = layer.GetSelection();
                    var count            = selectionfromMap.GetCount();
                    // MessageBox.Show($"Got layer {firstLayer.Name} with {count} selected features");
                    var filter = new QueryFilter {
                        ObjectIDs = selectionfromMap.GetObjectIDs()
                    };
                    if (count > 0)
                    {
                        using (RowCursor rowCursor = layer.Search(filter))
                        {
                            while (rowCursor.MoveNext())
                            {
                                long oid = rowCursor.Current.GetObjectID();
                                // get the shape from the row
                                Feature feature = rowCursor.Current as Feature;
                                if (feature.GetShape() is Polygon polygon)
                                {
                                    convertPolygon(layer, feature, polygon, rhinoDoc, origin);
                                }
                                else if (feature.GetShape() is Polyline polyline)
                                {
                                    convertPolyline(layer, feature, polyline, rhinoDoc, origin);
                                }
                                else if (feature.GetShape() is MapPoint point)
                                {
                                    convertPoint(layer, feature, point, rhinoDoc, origin);
                                }
                                else if (feature.GetShape() is Multipoint multiPoint)
                                {
                                    // TODO: treat multipoint as a group of points
                                }
                                else if (feature.GetShape() is Multipatch multiPatch)
                                {
                                    // TODO: treat multipoint as a group of patches
                                }
                                else
                                {
                                    // TODO: figure out other possible types inherited from ArcGIS.Core.Geometry
                                }
                                // MessageBox.Show("Found feature with attributes:\n" + string.Join("\n", feature.GetFields().Select(f => f.Name).ToList()));
                            }
                        }
                    }
                });
            }
        }
Пример #3
0
 /// <summary>
 /// Place point on feature layer
 /// </summary>
 /// <param name="operation">Edit operatio</param>
 /// <param name="point">Rhino Point3d</param>
 private static void showPoint(EditOperation operation, Point3d point, Point3d origin)
 {
     try
     {
         var layer = getFeatureLayer(FeatureLayerType.GH_Preview_Point);
         if (layer == null)
         {
             return;
         }
         MapPoint mp = RhinoUtil.ptToGis(point, origin);
         operation.Create(layer, mp);
         operation.ExecuteAsync();
     }
     catch
     {
     }
 }
Пример #4
0
        /// <summary>
        /// Copy compatible GH canvas preview components into ArcGIS
        /// </summary>
        /// <param name="document"></param>
        internal static void showDocumentPreview(RhinoDoc rhinoDoc)
        {
            try
            {
                // TODO: determine whether to purge existing GH_Preview geometry
                // on feature layers or append to that.
                var document = Grasshopper.Instances.DocumentServer.FirstOrDefault();
                if (document == null)
                {
                    return;
                }
                if (rhinoDoc == null)
                {
                    return;
                }
                var origin         = RhinoUtil.getOrigin(rhinoDoc);
                var previewObjects = document.Objects
                                     .OfType <IGH_ActiveObject>()
                                     .Where(o => !o.Locked && o is IGH_PreviewObject)
                                     .Select(o => o as IGH_PreviewObject)
                                     .Where(o => o.IsPreviewCapable)
                                     .ToList();

                var componentParams = previewObjects
                                      .Where(o => o is IGH_Component)
                                      .Select(o => o as IGH_Component)
                                      .Where(o => !o.Hidden)
                                      .SelectMany(o => o.Params.Output)
                                      .ToList();

                var otherParams = previewObjects
                                  .Where(o => o is IGH_Param)
                                  .Select(o => o as IGH_Param)
                                  .ToList();
                QueuedTask.Run(() =>
                {
                    var operation = new EditOperation();
                    componentParams.ForEach(p => showParam(operation, p, origin));
                    otherParams.ForEach(p => showParam(operation, p, origin));
                });
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message + ex.StackTrace);
            }
        }
Пример #5
0
        private void bExport_Click(object sender, RoutedEventArgs e)
        {
            var t = QueuedTask.Run(() =>
            {
                if (rhinoDoc != null)
                {
                    foreach (var rhobj in rhinoDoc.Objects.Where(o => o.IsSelected(false) > 0))
                    {
                        int layerIndex   = rhobj.Attributes.LayerIndex;
                        string layerName = rhinoDoc.Layers[layerIndex].Name;
                        // MessageBox.Show($"Got layer {layerName} with selected features");
                        var thisLayer = MapView.Active.Map.FindLayers(layerName).FirstOrDefault() as BasicFeatureLayer;
                        thisLayer     = (thisLayer == null) ? MapView.Active.Map.GetLayersAsFlattenedList().FirstOrDefault() as BasicFeatureLayer : thisLayer;

                        RhinoUtil.ThrowItOverTheFence(thisLayer, rhobj, rhinoDoc);
                    }
                }
            });
        }