Beispiel #1
0
        public static IPolycurve DensifyPolycurve(ref IPolycurve ipolycurve_0, ref int int_0)
        {
            IPolycurve polycurve = Utils3D.CreateClone(ipolycurve_0 as IClone) as IPolycurve;

            polycurve.Densify(Convert.ToDouble(polycurve.Length / (double)int_0), 0.0);
            return(polycurve);
        }
        void m_editEvents_OnCreateFeature(IObject obj)
        {
            // check if feature contains more than 2000 nodes/vertices
            //  applies to lines and polygons
            //  notify the user and offer a split
            // check if feature geometry is multi-part
            //  applies to lines and polygons
            //  notify the user and offer a conversion to relation

            IFeatureClass currentObjectFeatureClass = obj.Class as IFeatureClass;

            if ((currentObjectFeatureClass == null) || (currentObjectFeatureClass.EXTCLSID == null))
            {
                return;
            }

            // check if the current feature class being edited is acutally an OpenStreetMap feature class
            // all other feature class should not be touched by this extension
            UID osmEditorExtensionCLSID = currentObjectFeatureClass.EXTCLSID;

            if (osmEditorExtensionCLSID.Value.ToString().Equals("{65CA4847-8661-45eb-8E1E-B2985CA17C78}", StringComparison.InvariantCultureIgnoreCase) == false)
            {
                return;
            }

            IFeature currentFeature = obj as IFeature;

            if (currentFeature == null)
            {
                return;
            }


            ISegmentCollection segmentCollection = currentFeature.Shape as ISegmentCollection;
            bool densifyRequired = false;

            if (segmentCollection != null)
            {
                for (int segmentIndex = 0; segmentIndex < segmentCollection.SegmentCount; segmentIndex++)
                {
                    ISegment segment = segmentCollection.get_Segment(segmentIndex);

                    if (!(segment is Line))
                    {
                        densifyRequired = true;
                        break;
                    }
                }
            }


            if (densifyRequired)
            {
                IGeometryEnvironment4 geometryEnvironment = new GeometryEnvironmentClass() as IGeometryEnvironment4;

                double densifyTolerance   = geometryEnvironment.AutoDensifyTolerance;
                double deviationTolerance = geometryEnvironment.DeviationAutoDensifyTolerance;

                IPolycurve polycurve = currentFeature.Shape as IPolycurve;
                polycurve.Densify(densifyTolerance, deviationTolerance);

                currentFeature.Shape = polycurve;

                obj.Store();
            }
        }
        void m_editEvents_OnChangeFeature(IObject obj)
        {
            // check if feature contains more than 2000 nodes/vertices
            //  applies to lines and polygons
            //  notify the user and offer a split
            // check if feature geometry is multi-part
            //  applies to lines and polygons
            //  notify the user and offer a conversion to relation

            IFeatureClass currentObjectFeatureClass = obj.Class as IFeatureClass;

            if ((currentObjectFeatureClass == null) || (currentObjectFeatureClass.EXTCLSID == null))
            {
                return;
            }

            // check if the current feature class being edited is acutally an OpenStreetMap feature class
            // all other feature class should not be touched by this extension
            UID osmEditorExtensionCLSID = currentObjectFeatureClass.EXTCLSID;

            if (osmEditorExtensionCLSID.Value.ToString().Equals("{65CA4847-8661-45eb-8E1E-B2985CA17C78}", StringComparison.InvariantCultureIgnoreCase) == false)
            {
                return;
            }

            IFeature currentFeature = obj as IFeature;

            if (currentFeature == null)
            {
                return;
            }

            IPointCollection pointCollection = currentFeature.Shape as IPointCollection;

            if (pointCollection == null)
            {
                return;
            }

            // block changing features that are supporting features for multi-part geometries (relations)
            if (currentFeature.Shape is IPolygon || currentFeature.Shape is IPolyline)
            {
                if (((IFeatureChanges)currentFeature).ShapeChanged == true)
                {
                    int memberOFFieldIndex = currentFeature.Fields.FindField("osmMemberOf");
                    int membersFieldIndex  = currentFeature.Fields.FindField("osmMembers");
                    int osmIDFieldIndex    = currentFeature.Fields.FindField("OSMID");

                    long osmID = 0;

                    if (osmIDFieldIndex > -1)
                    {
                        object osmIDValue = currentFeature.get_Value(osmIDFieldIndex);

                        if (osmIDValue != DBNull.Value)
                        {
                            osmID = Convert.ToInt64(osmIDValue);
                        }
                    }

                    if (membersFieldIndex > -1)
                    {
                        ESRI.ArcGIS.OSM.OSMClassExtension.member[] relationMembers = _osmUtility.retrieveMembers(currentFeature, membersFieldIndex);

                        if (relationMembers != null)
                        {
                            if (relationMembers.Length > 0)
                            {
                                string abortMessage = String.Format(resourceManager.GetString("OSMEditor_FeatureInspector_multipartchangeparentconflictmessage"), osmID);
                                MessageBox.Show(abortMessage, resourceManager.GetString("OSMEditor_FeatureInspector_relationconflictcaption"), MessageBoxButtons.OK, MessageBoxIcon.Stop);
                                m_editor3.AbortOperation();
                            }
                        }
                    }

                    if (memberOFFieldIndex > -1)
                    {
                        List <string> isMemberOfList = _osmUtility.retrieveIsMemberOf(currentFeature, memberOFFieldIndex);
                        Dictionary <string, string> dictofParentsAndTypes = _osmUtility.parseIsMemberOfList(isMemberOfList);

                        StringBuilder typeAndIDString = new StringBuilder();
                        foreach (var item in dictofParentsAndTypes)
                        {
                            switch (item.Value)
                            {
                            case "rel":
                                typeAndIDString.Append(resourceManager.GetString("OSMEditor_FeatureInspector_relationidtext") + item.Key + ",");
                                break;

                            case "ply":
                                typeAndIDString.Append(resourceManager.GetString("OSMEditor_FeatureInspector_polygonidtext") + item.Key + ",");
                                break;

                            case "ln":
                                typeAndIDString.Append(resourceManager.GetString("OSMEditor_FeatureInspector_polylineidtext") + item.Key + ",");
                                break;

                            case "pt":
                                typeAndIDString.Append(resourceManager.GetString("OSMEditor_FeatureInspector_pointidtext") + item.Key + ",");
                                break;

                            default:
                                break;
                            }
                        }

                        if (typeAndIDString.Length > 0)
                        {
                            string parentsString = typeAndIDString.ToString(0, typeAndIDString.Length - 1);
                            string abortMessage  = String.Format(resourceManager.GetString("OSMEditor_FeatureInspector_multipartchangeconflictmessage"), osmID, parentsString);
                            MessageBox.Show(abortMessage, resourceManager.GetString("OSMEditor_FeatureInspector_relationconflictcaption"), MessageBoxButtons.OK, MessageBoxIcon.Stop);
                            m_editor3.AbortOperation();
                        }
                    }
                }
            }

            ISegmentCollection segmentCollection = currentFeature.Shape as ISegmentCollection;
            bool densifyRequired = false;

            for (int segmentIndex = 0; segmentIndex < segmentCollection.SegmentCount; segmentIndex++)
            {
                ISegment segment = segmentCollection.get_Segment(segmentIndex);

                if (!(segment is Line))
                {
                    densifyRequired = true;
                    break;
                }
            }


            if (densifyRequired)
            {
                IGeometryEnvironment4 geometryEnvironment = new GeometryEnvironmentClass() as IGeometryEnvironment4;

                double densifyTolerance   = geometryEnvironment.AutoDensifyTolerance;
                double deviationTolerance = geometryEnvironment.DeviationAutoDensifyTolerance;

                IPolycurve polycurve = currentFeature.Shape as IPolycurve;
                polycurve.Densify(densifyTolerance, deviationTolerance);

                currentFeature.Shape = polycurve;

                obj.Store();
            }
        }
        private byte[] AnalGeomBufferHandler(NameValueCollection boundVariables,
                                             JsonObject operationInput,
                                             string outputFormat,
                                             string requestProperties,
                                             out string responseProperties)
        {
            responseProperties = null;

            long?paramOID;
            bool found = operationInput.TryGetAsLong("OBJECTID", out paramOID);

            if (!found || !paramOID.HasValue)
            {
                throw new ArgumentNullException("OBJECTID invalido!");
            }

            long?paramBuffer1;

            found = operationInput.TryGetAsLong("bufferCerchio1", out paramBuffer1);
            if (!found || !paramBuffer1.HasValue)
            {
                throw new ArgumentNullException("Valore Buffer1 invalido!!");
            }

            long?paramBuffer2;

            found = operationInput.TryGetAsLong("bufferCerchio2", out paramBuffer2);
            if (!found || !paramBuffer2.HasValue)
            {
                throw new ArgumentNullException("Valore Buffer2 invalido!!");
            }

            long?paramBuffer3;

            found = operationInput.TryGetAsLong("bufferCerchio3", out paramBuffer3);
            if (!found || !paramBuffer3.HasValue)
            {
                throw new ArgumentNullException("Valore Buffer3 invalido!!");
            }

            this.RicavaInfoFc();

            IFeature feature = null;

            this.RicavaFeatureFiliare(paramOID.Value, out feature);

            Dictionary <long, IPolygon> dizGeometrieBuffer =
                this.CostruisciBuffer(feature, paramBuffer1.Value, paramBuffer2.Value, paramBuffer3.Value);

            List <IRecordSet2> listaRecordSet =
                this.AnalisiSpazialiBufferOper(dizGeometrieBuffer);

            JsonObject result = new JsonObject();

            result.AddJsonObject("interno",
                                 new JsonObject(Encoding.UTF8.GetString(Conversion.ToJson(listaRecordSet[0]))));
            result.AddJsonObject("centrale",
                                 new JsonObject(Encoding.UTF8.GetString(Conversion.ToJson(listaRecordSet[1]))));

            result.AddJsonObject("superiore",
                                 new JsonObject(Encoding.UTF8.GetString(Conversion.ToJson(listaRecordSet[2]))));

            #region Mi occupo di tirare fuori le Geometrie dei Buffer circolari e serializzarle
            List <IGeometry> listaGeometrie = new List <IGeometry>();
            foreach (KeyValuePair <long, IPolygon> coppia in dizGeometrieBuffer)
            {
                // ATTENZIONE!!!

                // GLI ARCOBJECTS (METODO CONVERSION - SOE_SUPPORT) NON GESTISCE L'INSERIMENTO DI CURVE NEL JSON.
                // UNA TRUE CURVE DEVE ESSERE SEMPLIFICATA - DENSIFICATA COME UN INSIEME DI SEGMENTI (es: shapefile)
                // PRIMA DI ESSERE RESTITUITA AL CLIENT!!

                IPolycurve polycurve = coppia.Value as IPolycurve;
                polycurve.Densify(5, 0);

                IGeometry geo = polycurve as IGeometry;
                geo.SpatialReference = ((IGeoDataset)fcClienti).SpatialReference;

                listaGeometrie.Add(geo);
            }

            object[] objArray = Helper.GetListJsonObjects(listaGeometrie);
            #endregion

            result.AddArray("geomBuffer", objArray);

            return(Encoding.UTF8.GetBytes(result.ToJson()));
        }