Example #1
0
        /// <summary>
        /// Returns two feature layers: one for the selected region and one for the childs.
        /// </summary>
        /// <param name="selectedRegion"></param>
        /// <returns></returns>
        public static List <ShapeFileFeatureLayer> GetFeatureLayers(Region selectedRegion)
        {
            List <ShapeFileFeatureLayer> aux = new List <ShapeFileFeatureLayer> {
                GetRegionFeatureLayer(selectedRegion)
            };

            List <Region> childRegions = RegionHelper.GetChilds(selectedRegion.IDRegion).GroupBy(r => r.ShapeFileName).Select(g => g.First()).ToList();

            aux.AddRange(from Region region in childRegions select GetRegionFeatureLayer(region));

            return(aux);
        }
Example #2
0
 public static Boolean TestServer()
 {
     try
     {
         Region region = RegionHelper.GetWorld();
         return(true);
     }
     catch (Exception)
     {
         return(false);
     }
 }
Example #3
0
        public static List <ShapeFileFeatureLayer> GetModelFeatureLayers(Model model, ref List <String> errors)
        {
            List <Region> modelRegions = RegionHelper.GetAllRelated(model.IDRegion);
            List <ShapeFileFeatureLayer> featureLayers = new List <ShapeFileFeatureLayer>();


            for (int i = 0; i < 8; i++)
            {
                List <Region> aux = modelRegions.Where(r => r.RegionLevel == i).GroupBy(r => r.ShapeFileName).Select(g => g.First()).ToList();

                foreach (Region region in aux)
                {
                    string shapefilePath = GetShapeFileFullPath(region);

                    if (!File.Exists(shapefilePath))
                    {
                        //the shapefile couldn't be found in the client. Try to get it from the server.
                        if (!DocumentHelper.GetRegionShapefilesFromServer(region))
                        {
                            errors.Add(region.RegionName + "||");
                        }
                    }

                    if (File.Exists(shapefilePath))
                    {
                        ShapeFileFeatureLayer shapeFileFeatureLayer = new ShapeFileFeatureLayer(shapefilePath)
                        {
                            Name = (aux.Count == 1 ? i.ToString() : i + "_" + region.RegionName)
                        };
                        RebuildIndexFile(shapeFileFeatureLayer);
                        featureLayers.Add(shapeFileFeatureLayer);
                    }
                }
            }
            return(featureLayers);
        }
Example #4
0
        /// <summary>
        /// Saves the shapefiles related to the model to the destination folder.
        /// </summary>
        /// <param name="model"></param>
        /// <param name="destinationFolder"></param>
        public static void SaveAllShapefilesInModel(Model model, DirectoryInfo destinationFolder)
        {
            List <Region> regionList        = new List <Region>();
            List <string> shapeFileNameList = new List <string>();
            Region        firstRegion       = RegionHelper.Get(model.IDRegion);

            regionList.Add(firstRegion);
            regionList.AddRange(RegionHelper.GetAllChilds(firstRegion.IDRegion));

            foreach (Region region in regionList)
            {
                if (shapeFileNameList.Contains(region.ShapeFileName))
                {
                    continue;
                }
                shapeFileNameList.Add(region.ShapeFileName);
            }

            if (shapeFileNameList.Count == 0)
            {
                return;
            }

            if (!Directory.Exists(destinationFolder.FullName))
            {
                Directory.CreateDirectory(destinationFolder.FullName);
            }

            foreach (string shapeFileName in shapeFileNameList)
            {
                if (!File.Exists(DirectoryAndFileHelper.ClientShapefilesFolder + shapeFileName))
                {
                    continue;
                }

                int regionLevelInt = -1;

                if (!int.TryParse(shapeFileName.Substring(0, 1), out regionLevelInt))
                {
                    continue;
                }

                RegionLevel regionLevel = RegionHelper.GetRegionLevelFromNumber(regionLevelInt);

                if (!Directory.Exists(destinationFolder.FullName + "\\" + regionLevelInt + "-" + regionLevel))
                {
                    Directory.CreateDirectory(destinationFolder.FullName + "\\" + regionLevelInt + "-" + regionLevel);
                }

                FileInfo auxFileInfo = new FileInfo(DirectoryAndFileHelper.ClientShapefilesFolder + shapeFileName);
                //shp
                if (File.Exists(auxFileInfo.FullName))
                {
                    File.Copy(auxFileInfo.FullName, destinationFolder.FullName + "\\" + regionLevelInt + "-" + regionLevel + "\\" + auxFileInfo.Name, true);
                }

                //shx
                string shxFileName = shapeFileName.ToLower().Replace(".shp", ".shx");
                auxFileInfo = new FileInfo(DirectoryAndFileHelper.ClientShapefilesFolder + shxFileName);
                if (File.Exists(auxFileInfo.FullName))
                {
                    File.Copy(auxFileInfo.FullName, destinationFolder.FullName + "\\" + regionLevelInt + "-" + regionLevel + "\\" + auxFileInfo.Name, true);
                }

                //dbf
                string dbfFileName = shapeFileName.ToLower().Replace(".shp", ".dbf");
                auxFileInfo = new FileInfo(DirectoryAndFileHelper.ClientShapefilesFolder + dbfFileName);
                if (File.Exists(auxFileInfo.FullName))
                {
                    File.Copy(auxFileInfo.FullName, destinationFolder.FullName + "\\" + regionLevelInt + "-" + regionLevel + "\\" + auxFileInfo.Name, true);
                }
            }
        }