示例#1
0
        /// <summary>
        /// Get from input of operation the SegmentExtension
        /// </summary>
        /// <param name="operationInput">input of operation</param>
        /// <returns>value of SegmentExtension</returns>
        private static esriSegmentExtension GetSegmentExtension(JsonObject operationInput)
        {
            string segmentExtensionValue;
            esriSegmentExtension segmentExtension = esriSegmentExtension.esriNoExtension;
            bool found = operationInput.TryGetString("segmentExtension", out segmentExtensionValue);

            if (found && !string.IsNullOrEmpty(segmentExtensionValue))
            {
                if (Enum.IsDefined(typeof(esriSegmentExtension), segmentExtensionValue))
                {
                    segmentExtension = (esriSegmentExtension)Enum.Parse(typeof(esriSegmentExtension), segmentExtensionValue, true);
                }
            }

            return(segmentExtension);
        }
        private bool CalculateHouseNumber()
        {
            try
            {
                IPolyline            pline            = Centerline.Shape as IPolyline;
                ICurve               curve            = pline as ICurve;
                esriSegmentExtension segEx            = esriSegmentExtension.esriNoExtension;
                IFeature             f                = SelectedPoint;
                IPoint               ObservationPoint = trackgeom.ToPoint;
                IPoint               inPoint          = intersectionPoint;
                IPoint               outPoint         = new PointClass();
                double               distance         = 0.0d;
                double               distancefrom     = 0.0d;
                bool onright = false;
                curve.QueryPointAndDistance(segEx, ObservationPoint, false, outPoint, ref distance, ref distancefrom, ref onright);


                //double a = GetAreaOfTriangle(pline.FromPoint, pline.ToPoint, inPoint, outPoint, distancefrom);
                //double a = GetThreePointAngle(pline.FromPoint.X, pline.FromPoint.Y, pline.ToPoint.X, pline.ToPoint.Y, inPoint.X, inPoint.Y);
                //onright = (a > 0);

                int start_number = 0;
                int n1           = Convert.ToInt32(Centerline.get_Value(Globals.CenterlineFields.FromLeft).ToString());
                int n2           = Convert.ToInt32(Centerline.get_Value(Globals.CenterlineFields.FromRight).ToString());
                start_number = Math.Min(n1, n2);

                int n3         = Convert.ToInt32(Centerline.get_Value(Globals.CenterlineFields.ToLeft).ToString());
                int n4         = Convert.ToInt32(Centerline.get_Value(Globals.CenterlineFields.ToRight).ToString());
                int end_number = 0;
                end_number = Math.Max(n3, n4);

                int total_addresses = end_number - start_number;

                double apu               = curve.Length / total_addresses;
                double lengthIndex       = Math.Abs(distance / apu);
                int    housenumberstoadd = Convert.ToInt32(Math.Round(lengthIndex, 0));



                IPolyline p = (IPolyline)Centerline.Shape;

                FlashGeometry(ObservationPoint);

                if (onright)
                {
                    int x = start_number + housenumberstoadd;
                    if (x % 2 == 0)
                    {
                        HouseNumber = x - 1;
                        return(true);
                    }
                    else
                    {
                        HouseNumber = x;
                        return(true);
                    }
                }
                else
                {
                    int x = start_number + housenumberstoadd;
                    if (x % 2 == 0)
                    {
                        HouseNumber = x;
                        return(true);
                    }
                    else
                    {
                        HouseNumber = x - 1;
                        return(true);
                    }
                }
                //return start_number + housenumberstoadd;
            }
            catch (Exception ex)
            {
                log.WriteError(ex, TAG, System.Security.Principal.WindowsIdentity.GetCurrent().Name, null);
                MessageBox.Show(ex.Message);
                return(false);
            }
        }
        private int CalculateHouseNumber(IPoint p)
        {
            try
            {
                ITopologicalOperator to = (ITopologicalOperator)p;
                double    buffsize      = .01 * mDoc.FocusMap.MapScale;
                IGeometry g             = to.Buffer(buffsize);
                FlashGeometry(g);

                mMap.SelectByShape(g, ArcMap.ThisApplication.SelectionEnvironment, true);

                IFeatureSelection fsel = Globals.CenterlineLayer as IFeatureSelection;
                if (fsel.SelectionSet.Count > 0)
                {
                    IEnumIDs pEnum = fsel.SelectionSet.IDs;
                    int      oid   = pEnum.Next();
                    IFeature feat  = Globals.CenterlineLayer.FeatureClass.GetFeature(oid);
                    Centerline = feat;

                    IPolyline            pline = feat.Shape as IPolyline;
                    ICurve               curve = pline as ICurve;
                    esriSegmentExtension segEx = esriSegmentExtension.esriNoExtension;
                    ITopologicalOperator to2   = g as ITopologicalOperator;
                    IMultipoint          mp    = to2.Intersect(curve, esriGeometryDimension.esriGeometry0Dimension) as IMultipoint;
                    IPointCollection     pc    = mp as IPointCollection;

                    IPoint ObservationPoint = p;
                    IPoint inPoint          = pc.get_Point(0);
                    IPoint outPoint         = new PointClass();
                    double distance         = 0.0d;
                    double distancefrom     = 0.0d;
                    bool   onright          = false;
                    curve.QueryPointAndDistance(segEx, ObservationPoint, false, outPoint, ref distance, ref distancefrom, ref onright);


                    intersectionPoint = outPoint;
                    //double a = GetAreaOfTriangle(pline.FromPoint, pline.ToPoint, inPoint, outPoint, distancefrom);
                    //double a = GetThreePointAngle(pline.FromPoint.X, pline.FromPoint.Y, pline.ToPoint.X, pline.ToPoint.Y, inPoint.X, inPoint.Y);
                    //onright = (a > 0);

                    int start_number = 0;
                    int n1           = Convert.ToInt32(Centerline.get_Value(Globals.CenterlineFields.FromLeft).ToString());
                    int n2           = Convert.ToInt32(Centerline.get_Value(Globals.CenterlineFields.FromRight).ToString());
                    start_number = Math.Min(n1, n2);

                    int n3         = Convert.ToInt32(Centerline.get_Value(Globals.CenterlineFields.ToLeft).ToString());
                    int n4         = Convert.ToInt32(Centerline.get_Value(Globals.CenterlineFields.ToRight).ToString());
                    int end_number = 0;
                    end_number = Math.Max(n3, n4);

                    int total_addresses = end_number - start_number;

                    double apu               = curve.Length / total_addresses;
                    double lengthIndex       = Math.Abs(distance / apu);
                    int    housenumberstoadd = Convert.ToInt32(Math.Round(lengthIndex, 0));

                    IPolyline pline1 = (IPolyline)feat.Shape;

                    FlashGeometry(ObservationPoint);


                    int hn = 0;

                    if (onright == false)
                    {
                        int x = start_number + housenumberstoadd;
                        if (x % 2 == 0)
                        {
                            hn = x - 1;
                        }
                        else
                        {
                            hn = x;
                        }
                    }
                    else
                    {
                        int x = start_number + housenumberstoadd;
                        if (x % 2 == 0)
                        {
                            hn = x;
                        }
                        else
                        {
                            hn = x - 1;
                        }
                    }

                    return(hn);
                }
                else
                {
                    return(0);
                }
            }
            catch (Exception ex)
            {
                log.WriteError(ex, TAG, System.Security.Principal.WindowsIdentity.GetCurrent().Name, null);
                return(0);
            }
        }
示例#4
0
        /// <summary>
        /// Handler operation Identify Route Ex
        /// </summary>
        /// <param name="boundVariables">list of variables bound</param>
        /// <param name="operationInput">input of operation</param>
        /// <param name="outputFormat">format of output</param>
        /// <param name="requestProperties">list of request properties</param>
        /// <param name="responseProperties">list of response properties </param>
        /// <returns>response in byte</returns>
        private byte[] IdentifyRouteExOperHandler(NameValueCollection boundVariables, JsonObject operationInput, string outputFormat, string requestProperties, out string responseProperties)
        {
            responseProperties = "{\"Content-Type\" : \"application/json\"}";
            string methodName   = MethodBase.GetCurrentMethod().Name;
            int    routeLayerID = Convert.ToInt32(boundVariables["RouteLayersID"], CultureInfo.InvariantCulture);

            esriUnits            routeMeasureUnit = DSUtility.GetMeasureUnit(operationInput, MeasureUnit.routeMeasureUnit);
            esriSegmentExtension segmentExtension = DSUtility.GetSegmentExtension(operationInput);
            IFeatureClass        featureClass     = this.GetRouteFeatureClass(routeLayerID);

            JsonObject jsonLocation;

            if (!operationInput.TryGetJsonObject("location", out jsonLocation))
            {
                throw new ArgumentException("Invalid location", methodName);
            }

            IPoint location = Conversion.ToGeometry(jsonLocation, esriGeometryType.esriGeometryPoint) as IPoint;

            if (location == null)
            {
                throw new ArgumentException("Invalid location", methodName);
            }

            string  routeIDFieldNameValue = DSUtility.GetRouteIDFieldName(operationInput);
            IFields fields     = featureClass.Fields;
            int     indexField = fields.FindField(routeIDFieldNameValue);

            if (indexField == -1)
            {
                throw new DynamicSegmentationException(string.Format(CultureInfo.InvariantCulture, "routeIDFieldName {0} not found!", routeIDFieldNameValue));
            }

            object routeID;
            bool   found = operationInput.TryGetObject("routeID", out routeID);

            if (!found)
            {
                throw new DynamicSegmentationException("routeID not valid");
            }

            double?tolerance;

            found = operationInput.TryGetAsDouble("tolerance", out tolerance);
            if (!found || !tolerance.HasValue)
            {
                tolerance = 0.0;
            }

            IField field = fields.get_Field(indexField);

            this.CheckRouteID(routeID, field);

            IRouteLocator2 routeLocator = DSUtility.GetRouteLocator(featureClass, routeIDFieldNameValue, routeMeasureUnit);

            IQueryFilter queryFilter = new QueryFilterClass();

            queryFilter.SubFields = routeLocator.RouteIDFieldName;
            queryFilter.AddField(routeLocator.RouteFeatureClass.ShapeFieldName);
            string where            = string.Format("{0} = {1}{2}{1}", routeLocator.RouteIDFieldNameDelimited, routeLocator.RouteIDIsString ? "'" : string.Empty, routeID);
            queryFilter.WhereClause = where;

            IPoint         locationNearest = null;
            IFeatureCursor featureCursor   = null;

            try
            {
                featureCursor = routeLocator.RouteFeatureClass.Search(queryFilter, true);
                IFeature featureRoute = featureCursor.NextFeature();
                if (featureRoute == null)
                {
                    throw new DynamicSegmentationException(string.Format(CultureInfo.InvariantCulture, "Feature with value {0} not found!", routeID));
                }

                IProximityOperator proximityOperator = featureRoute.ShapeCopy as IProximityOperator;
                locationNearest = proximityOperator.ReturnNearestPoint(location, segmentExtension);
            }
            catch
            {
                throw;
            }
            finally
            {
                if (featureCursor != null)
                {
                    Marshal.ReleaseComObject(featureCursor);
                }
            }

            IEnvelope envelope = locationNearest.Envelope;

            envelope.Expand(tolerance.Value, tolerance.Value, false);

            IRouteMeasurePointLocation routeMeasurePointLocation = new RouteMeasurePointLocationClass();
            IRouteLocation             routeLocation;
            IFeature   feature;
            JsonObject result = new JsonObject();

            List <JsonObject>        measures   = new List <JsonObject>();
            IEnumRouteIdentifyResult enumResult = routeLocator.Identify(envelope, where);

            for (int i = 1; i <= enumResult.Count; i++)
            {
                enumResult.Next(out routeLocation, out feature);
                routeMeasurePointLocation = (IRouteMeasurePointLocation)routeLocation;
                JsonObject measure = new JsonObject();
                measure.AddString("routeID", routeLocation.RouteID.ToString());
                measure.AddDouble("measure", routeMeasurePointLocation.Measure);
                measure.AddJsonObject("location", Conversion.ToJsonObject(locationNearest, true));
                measures.Add(measure);
            }

            result.AddArray("location", measures.ToArray());

            return(result.JsonByte());
        }
示例#5
0
        /// <summary>
        /// Extends the specified feature.
        /// </summary>
        /// <param name="feature">The feature to extend</param>
        /// <param name="searchTolerance">The search tolerance.</param>
        public void Extend(IFeature feature, double searchTolerance)
        {
            try
            {
                IPolyline polyLine = (IPolyline)feature.Shape;

                // TODO: drop a TargetItem from the list if it has been extended.
                foreach (IFeatureLayer layer in this.FeatureLayers)
                {
                    List <TargetItem> targetFeatures = GetTargetFeatures(layer, searchTolerance, (IGeometry)polyLine);

                    if (targetFeatures.Count.Equals(1))
                    {
                        TargetItem targetFeatureItem = targetFeatures[0];

                        IConstructCurve constructCurve = new PolylineClass();

                        esriSegmentExtension ext = esriSegmentExtension.esriNoExtension;

                        if (targetFeatures[0].nearestEndPoint.Equals(LineEndPoint.From))
                        {
                            ext = esriSegmentExtension.esriExtendAtFrom;
                        }
                        else
                        {
                            ext = esriSegmentExtension.esriExtendAtTo;
                        }

                        bool extPerformed = false;

                        constructCurve.ConstructExtended((ICurve)polyLine, (ICurve)targetFeatureItem.targetFeature.Shape, (int)esriCurveExtension.esriRelocateEnds, ref extPerformed);

                        if (extPerformed)
                        {
                            IPolyline newLine = (IPolyline)constructCurve;

                            System.Diagnostics.Debug.WriteLine("original length=  " + polyLine.Length.ToString());
                            System.Diagnostics.Debug.WriteLine("newLine length=  " + newLine.Length.ToString());

                            OnExtendMessage("Feature {OID} extended!!!", feature);

                            if (!this.Simulation)
                            {
                                UpdateGeometry(feature, (IGeometry)newLine);
                            }

                            CounterExtended++;
                        }
                        else
                        {
                            OnExtendMessage("Feature {OID}  could not be extended.", feature);
                            CounterNotExtended++;
                        }
                    }
                    else if (targetFeatures.Count.Equals(0))
                    {
                        OnExtendMessage("Feature {OID}  is not within any features in: " + layer.Name, feature);
                        CounterNotExtended++;
                    }
                    else
                    {
                        // TODO: handle multiple targets.
                        OnExtendMessage("Feature {OID}  is within multiple features in: " + layer.Name + ".  Cannot extend this feature.", feature);
                        CounterNotExtended++;
                    }
                }
            }
            catch (Exception ex)
            {
                System.Diagnostics.Trace.WriteLine(ex.StackTrace);
                throw;
            }
        }