Пример #1
0
        public List <GraphicDTO> GetDriveTimePolygons(MapPointDTO point)
        {
            try
            {
                var res    = new List <GraphicDTO>();
                var config = new ConfigurationModule.ConfigurationModule();
                config.Initialize();
                var           identify              = new IdentifyModule.IdentifyModule(config, null);
                var           spcRef                = new SpatialReference(4326);
                SymbolCreator _symbolCreator        = new SymbolCreator(config);
                var           networkAnalysisModule = new NetworkAnalysisModule.NetworkAnalysisModule(identify, config);
                // point.Extent.Extent
                var     mobileAssetIdentifyLayerConfig = config.IdentifyConfig.MapServices.SelectMany(x => x.Layers).FirstOrDefault(x => x.ID == 1);
                var     actionConfig = mobileAssetIdentifyLayerConfig.Actions.FirstOrDefault(x => x.Type == ActionType.ServiceArea.ToString());
                var     timeRanges   = actionConfig.TimeRanges.Select(x => Convert.ToDouble(x.Time)).ToArray();
                Graphic g            = new Graphic();
                g.Geometry = new MapPoint(point.Longitude, point.Latitude, spcRef);
                List <Feature> serviceAreaPolygons    = networkAnalysisModule.GetServiceArea(spcRef, g, timeRanges).Result;
                var            polygonHighlightConfig = config.ZoomAndHighlightConfig.Highlight.Symbols.Polygon;
                if (serviceAreaPolygons != null && serviceAreaPolygons.Any())
                {
                    for (int i = 0; i < serviceAreaPolygons.Count; i++)
                    {
                        var polygonColor = actionConfig.TimeRanges[i].Color;
                        var symbol       = _symbolCreator.CreatePolygonSymbol(polygonColor, polygonHighlightConfig.OutlineColor, polygonHighlightConfig.Thickness);

                        //var graphic = new Graphic()
                        //{
                        //    Symbol = symbol,
                        //    Geometry = serviceAreaPolygons[i].Geometry
                        //};
                        var grpDto = new GraphicDTO();
                        grpDto.polygonObject = serviceAreaPolygons[i].Geometry.ToJson();
                        grpDto.symbolObject  = symbol.ToJson();
                        res.Add(grpDto);
                    }
                }
                return(res);
            }
            catch (Exception ex)
            {
            }
            return(null);
        }
Пример #2
0
        public static bool IsRelocatable(string aFileName)
        {
            bool ret = false;

            //
            using (StreamReader reader = new StreamReader(aFileName))
            {
                string line = reader.ReadLine();
                while (line != null)
                {
                    SymbolCreator.BasicSymbol symbol = SymbolCreator.Parse(line);
                    if (symbol != null)
                    {
                        ret = (symbol.iAddress == 0);
                        break;
                    }
                    //
                    line = reader.ReadLine();
                }
            }
            //
            return(ret);
        }
        // *********** Command Line Error Codes & Meaning *************

        /// <summary>
        /// Copies feature from inputFeatureClassString to Military Feature destinationGeodatabase
        /// Set the Representation Rule ID based on sidcFieldName field
        /// </summary>
        /// <returns>Success: True/False</returns>
        public bool Process(string inputFeatureClassString,
                            string destinationGeodatabase,
                            string sidcFieldName,
                            string standard)
        {
            bool success = false;

            string installPath = new System.IO.FileInfo(System.Reflection.Assembly.GetExecutingAssembly().Location).DirectoryName;
            string sidcToFeatureClassRulesDataFile = System.IO.Path.Combine(installPath, @"Data\SymbolIDToFeatureClassRules.xml");

            string fieldMappingDataFile = System.IO.Path.Combine(installPath, @"Data\FieldMapping.xml");

            InitializeFieldMapping(fieldMappingDataFile);

            mapper = new SicToFeatureClassMapper(sidcToFeatureClassRulesDataFile);

            if (!mapper.Initialized)
            {
                lastErrorCode = 0; detailedErrorMessage = "Failed to load mapping data file " + sidcToFeatureClassRulesDataFile;
                Console.WriteLine(detailedErrorMessage);
                return(false);
            }

            IFeatureClass inputFeatureClass = getFeatureClassFromName(inputFeatureClassString);

            if (inputFeatureClass == null)
            {
                lastErrorCode = 2; detailedErrorMessage = "Could not open Input Feature Class: " + inputFeatureClassString;
                Console.WriteLine(detailedErrorMessage);
                return(false);
            }

            if (inputFeatureClass.FindField(sidcFieldName) < 0)
            {
                lastErrorCode = 6; detailedErrorMessage = "Could not find [SIDC] field: " + sidcFieldName + " in Input Feature Class: " + inputFeatureClassString;
                Console.WriteLine(detailedErrorMessage);
                return(false);
            }

            HashSet <string> matchedRules = getMatchedRules(inputFeatureClass, sidcFieldName);

            if (matchedRules.Count <= 0)
            {
                lastErrorCode = 3; detailedErrorMessage = "No matching military features found in input: " + inputFeatureClassString;
                Console.WriteLine(detailedErrorMessage);
                return(false);
            }

            militaryFeatures = new MilitaryFeatureClassHelper();
            militaryFeatures.FullWorkspacePath = destinationGeodatabase;
            IFeatureWorkspace ws = militaryFeatures.Workspace;

            if (!militaryFeatures.Initialized)
            {
                lastErrorCode = 4; detailedErrorMessage = "Output Workspace could not be found/opened: " + destinationGeodatabase;
                Console.WriteLine(detailedErrorMessage);
                return(false);
            }

            symbolCreator = new SymbolCreator(standard);
            bool initialized = symbolCreator.Initialize();

            if (!initialized)
            {
                lastErrorCode = 7; detailedErrorMessage = "Could not load required Style Files. Check ArcGIS/Styles folder.";
                Console.WriteLine("Failed to initialize - could not load required Style Files");
                return(false);
            }

            // where the main work is done of updating the output
            success = updateMatchedRules(matchedRules, inputFeatureClass, sidcFieldName);

            return(success);
        }
        /// <summary>
        /// Set the Representation Rule ID based on sidc field of a
        /// Military Feature destinationGeodatabase/featurelayer
        /// </summary>
        /// <returns>Success: True/False</returns>
        public bool CalculateRepRulesFromSidc(string outputMilitaryFeatureClassString, string sidcFieldName,
                                              string standard)
        {
            bool success = false;

            MilitaryFeatureClassHelper.SIDC_FIELD_NAME2 = sidcFieldName;

            symbolCreator = new SymbolCreator(standard);
            bool initialized = symbolCreator.Initialize();

            if (!initialized)
            {
                lastErrorCode = 7; detailedErrorMessage = "Could not load required Style Files. Check ArcGIS/Styles folder.";
                Console.WriteLine("Failed to initialize - could not load required Style Files");
                return(false);
            }

            militaryFeatures = new MilitaryFeatureClassHelper();
            IFeatureClass outputFeatureClass = militaryFeatures.GetFeatureClassByName(outputMilitaryFeatureClassString);

            if (!militaryFeatures.Initialized || (outputFeatureClass == null))
            {
                lastErrorCode = 4; detailedErrorMessage = "Output FeatureClass could not be found/opened: " + outputMilitaryFeatureClassString;
                Console.WriteLine(detailedErrorMessage);
                return(false);
            }

            if (!militaryFeatures.IsFeatureClassLockable(outputFeatureClass))
            {
                // if a schema lock can't be obtained for feature class then bail on them all
                lastErrorCode = 5; detailedErrorMessage = string.Format("Exclusive Schema Lock can not be obtained for output feature class found for Rule:{0}", outputMilitaryFeatureClassString);
                Console.WriteLine(detailedErrorMessage);
                return(false);
            }

            ////////////////////////////////////////////////////////////
            // Initialization/Verification complete, now do processing

            repRulesWereAdded = false;

            ///////////////////////////////////////////////////////////////////
            // DEBUG SWITCH: allows testing without writing the output to the feature class
            const bool DEBUG_DONT_WRITE_OUTPUT = false; //  true;
            ///////////////////////////////////////////////////////////////////

            ////////////////////////////////////////////////////////////
            // TRICKY: Handle the 2 different output SIC/SIDC names in Military Features
            int sicFieldIndex = outputFeatureClass.Fields.FindField(MilitaryFeatureClassHelper.SIDC_FIELD_NAME1);

            if (sicFieldIndex < 0)
            {
                sicFieldIndex = outputFeatureClass.Fields.FindField(MilitaryFeatureClassHelper.SIDC_FIELD_NAME2);
                if (sicFieldIndex < 0)
                {
                    lastErrorCode = 6; detailedErrorMessage = string.Format("ABORTING: Could not find SIDC field in output");
                    Console.WriteLine(detailedErrorMessage);
                    return(false);
                }
            }
            ////////////////////////////////////////////////////////////

            // Start Editing
            IWorkspaceEdit workspaceEdit = militaryFeatures.Workspace as IWorkspaceEdit;

            if (workspaceEdit == null)
            {
                lastErrorCode = 5; detailedErrorMessage = string.Format("Exclusive Schema Lock can not be obtained for output feature class found for Rule:{0}", outputMilitaryFeatureClassString);
                Console.WriteLine(detailedErrorMessage);
                return(false);
            }

            workspaceEdit.StartEditing(false);
            workspaceEdit.StartEditOperation();

            IRepresentationClass repClass = militaryFeatures.GetRepresentationClassForFeatureClass(outputFeatureClass);

            if (repClass == null)
            {
                Console.WriteLine("ABORTING: RepresentationClass not found in output");
                return(false);
            }

            // setup insert cursor
            IFeatureCursor featureCursor  = outputFeatureClass.Update(null, true);
            IFeature       currentFeature = featureCursor.NextFeature();

            int featureCount = 0;

            while (currentFeature != null)
            {
                string sidc = currentFeature.get_Value(sicFieldIndex) as string;

                if (!symbolCreator.IsValidSic(sidc))
                {
                    if (string.IsNullOrEmpty(sidc) || (sidc.Length <= 0))
                    {
                        Console.WriteLine("Skipping empty SIDC");
                    }
                    else
                    {
                        Console.WriteLine("Skipping invalid SIDC: " + sidc);
                    }

                    currentFeature = featureCursor.NextFeature();
                    continue;
                }

                featureCount++;

                IFeatureBuffer featureBuffer = currentFeature as IFeatureBuffer;

                processSidc(repClass, featureBuffer, sidc);

                if (!DEBUG_DONT_WRITE_OUTPUT)
                {
                    featureCursor.UpdateFeature(currentFeature);
                }

                currentFeature = featureCursor.NextFeature();
            }

            if (!DEBUG_DONT_WRITE_OUTPUT)
            {
                featureCursor.Flush();
            }

            workspaceEdit.StopEditOperation();
            workspaceEdit.StopEditing(true);

            // Release the cursors to remove the lock on the data.
            System.Runtime.InteropServices.Marshal.ReleaseComObject(featureCursor);
            featureCursor = null;

            if (!DEBUG_DONT_WRITE_OUTPUT)
            {
                // looks totally nonsensical - but this forces any new rules to written
                if (repRulesWereAdded)
                {
                    repClass.RepresentationRules = repClass.RepresentationRules;
                }
            }

            success = true;

            return(success);
        }
 public SymbolExporter(string standard)
 {
     sc = new SymbolCreator(standard);
     sc.Initialize();
 }