Esempio n. 1
0
        internal static GeoAPI.Geometries.IGeometry GetGeometryByCode(string file, string shapeColumn, string code)
        {
            var           features = ShapeFile.ReadShapefile(file + ".shp");
            List <string> invalid  = new List <string>();
            List <string> noParent = new List <string>();
            int           row      = 0;

            foreach (var feature in features)
            {
                row++;
                string currentCode;
                if (feature.Attributes[shapeColumn] != null)
                {
                    currentCode = feature.Attributes[shapeColumn].ToString();
                }
                else
                {
                    currentCode = null;
                }

                if (string.IsNullOrEmpty(currentCode))
                {
                    throw new MessageException("El valor para el código no puede se nulo. Fila: " + row.ToString());
                }
                if (currentCode == code)
                {
                    return(feature.Geometry);
                }
            }
            return(null);
        }
Esempio n. 2
0
        internal static Dictionary <string, IGeometry> GetGeometryDictionary(string file, string shapeColumn)
        {
            Dictionary <string, IGeometry> ret = new Dictionary <string, IGeometry>();
            var           features             = ShapeFile.ReadShapefile(file + ".shp");
            List <string> invalid  = new List <string>();
            List <string> noParent = new List <string>();
            int           row      = 0;

            foreach (var feature in features)
            {
                row++;
                string currentCode;
                if (feature.Attributes[shapeColumn] != null)
                {
                    currentCode = feature.Attributes[shapeColumn].ToString();
                }
                else
                {
                    currentCode = null;
                }

                if (string.IsNullOrEmpty(currentCode))
                {
                    throw new MessageException("El valor para el código no puede se nulo. Fila: " + row.ToString());
                }
                ret.Add(currentCode, feature.Geometry);
            }
            return(ret);
        }
Esempio n. 3
0
        private void SaveItems(Dictionary <string, int> ci)
        {
            if (!fileAdded)
            {
                return;
            }

            Progress.Caption = "Leyendo ítems";
            var features = ShapeFile.ReadShapefile(Basename + ".shp");

            Progress.Caption = "Preparando ítems";

            current.ClippingRegionItems.Clear();
            Progress.Total = 0;
            Progress.Total = features.Count;
            foreach (var feature in features)
            {
                ClippingRegionItem item = new ClippingRegionItem();
                item.Centroid = (Point)feature.Geometry.Centroid;
                item.Code     = feature.Attributes[iCode].ToString();
                if (iCaption != "")
                {
                    item.Caption = feature.Attributes[iCaption].ToString();
                }
                if (item.Caption.Contains("\n"))
                {
                    item.Caption = item.Caption.Split('\n')[0];
                }
                if (ci != null)
                {
                    var parent = feature.Attributes[iParent].ToString();
                    item.Parent = new ClippingRegionItem(ci[parent]);
                }
                else
                {
                    item.Parent = country;
                }

                item.Geometry   = (Geometry)feature.Geometry;
                item.GeometryR1 = (Geometry)Simplifications.Simplify(feature.Geometry, QualityEnum.High);

                item.ClippingRegion = current;
                current.ClippingRegionItems.Add(item);
                Progress.Increment();
            }

            Progress.Caption = "Guardando ítems";

            var sql = InsertGenerator.FromList(current.ClippingRegionItems);

            context.Data.Session.SqlActions.BulkInsert(sql, Progress);
            context.Data.Session.Flush();
            current.ClippingRegionItems.Clear();
        }
        private void frmTestProject_Load(object sender, EventArgs e)
        {
            string fi1 = @"C:\Users\Administrator\Documents\ArcGIS\Mapas consistidos\Finales\2010 - Cartografia\Provincias 2010\provincias2010";
            string fi2 = @"C:\Users\Administrator\Documents\ArcGIS\Mapas consistidos\Finales\2010 - Cartografia\Radios2010\radios2010.shp";

            var features1 = ShapeFile.ReadShapefile(fi1);
            var features2 = ShapeFile.ReadShapefile(fi2);
            var f1        = features1[0];
            var f2        = features2[0];
            var v         = new ArrayList()
            {
                f1, f2
            };

            f1 = f2;
        }
Esempio n. 5
0
        public static void ValidateParentAndShapes(Progress Progress,
                                                   Dictionary <string, int> items, string file, string codeColumn, string iParent, bool skipOrphans = false)
        {
            medea.context.Data.Session.Ping();
            List <NetTopologySuite.Features.Feature> features;
            bool validateGeo = true;

            if (file.EndsWith(".shp", System.StringComparison.InvariantCultureIgnoreCase))
            {
                features = ShapeFile.ReadShapefile(file);
            }
            else if (file.EndsWith(".dbf", System.StringComparison.InvariantCultureIgnoreCase))
            {
                features    = ShapeFile.ReadDbasefile(file);
                validateGeo = false;
            }
            else
            {
                throw new Exception("Invalid extension.");
            }
            ValidateFeatures(Progress, items, codeColumn, iParent, features, validateGeo, skipOrphans);
            medea.context.Data.Session.Ping();
        }
Esempio n. 6
0
        private void SaveItems(Dictionary <string, int> ci)
        {
            if (!fileAdded)
            {
                return;
            }

            Progress.Caption = "Guardando ítems";

            //Trae todos los items de la geografía padre para asociar.
            current.GeographyItems.Clear();
            Progress.Total = 0;
            var features = ShapeFile.ReadShapefile(Basename + ".shp");

            if (dbfMissingFilename != null)
            {
                var featuresMissing = ShapeFile.ReadDbasefile(dbfMissingFilename);
                features.AddRange(featuresMissing);
            }
            Progress.Total = features.Count;
            Dictionary <string, bool> done = new Dictionary <string, bool>();

            int n = 0;
            List <GeographyItem> l = new List <GeographyItem>();

            foreach (var feature in features)
            {
                GeographyItem item = new GeographyItem();
                if (iHousehold != "")
                {
                    item.Households = ParseOrZero(iHousehold, feature);
                }
                if (iChildren != "")
                {
                    item.Children = ParseOrZero(iChildren, feature);
                }
                if (iPopulation != "")
                {
                    item.Population = ParseOrZero(iPopulation, feature);
                }
                if (iUrbanity != "")
                {
                    item.Urbanity = UrbanityEnumFromInt(ParseOrZero(iUrbanity, feature));
                }
                else
                {
                    item.Urbanity = UrbanityEnum.None;
                }
                item.Code = feature.Attributes[iCode].ToString();
                if (iCaption != "")
                {
                    item.Caption = feature.Attributes[iCaption].ToString();
                }

                if (ci != null)
                {
                    var parent = feature.Attributes[iParent].ToString();
                    item.Parent = new GeographyItem(ci[parent]);
                }

                item.Geometry = (Geometry)feature.Geometry;
                if (feature.Geometry != null)
                {
                    item.AreaM2   = Projections.CalculateM2Area(feature.Geometry);
                    item.Centroid = (Point)feature.Geometry.Centroid;

                    Simplifications.FillSimplifiedGeometries(item.Geometry, item);
                }
                else
                {
                    throw new Exception("La geometría no puede ser nula.");
                }

                item.Geography = current;
                if (done.ContainsKey(item.Code) == false)
                {
                    l.Add(item);
                    done[item.Code] = true;
                    if (n % 100 == 99)
                    {
                        string sql = InsertGenerator.FromList(l);
                        context.Data.Session.SqlActions.ExecuteNonQuery(sql);
                        l.Clear();
                    }
                    n++;
                }
                Progress.Increment();
            }
            if (l.Count > 0)
            {
                string sql = InsertGenerator.FromList(l);
                context.Data.Session.SqlActions.ExecuteNonQuery(sql);
            }
            string updateAverage = "UPDATE `geography` SET geo_area_avg_m2=(select avg(gei_area_m2) from "
                                   + "geography_item where gei_geography_id = geo_id) WHERE geo_id = " + current.Id.Value.ToString();

            context.Data.Session.SqlActions.ExecuteNonQuery(updateAverage);
            // esta formula es cualquier cosa, que fitea más o menos 6 como maxzoom de provincias y 11 como maxzoom de departamentos.
            //string updateMaxZoom = "update geography set geo_max_zoom = truncate (16-(power(geo_area_avg_m2, .25) / 60),0) "
            //		+ "WHERE geo_id = " + current.Id.Value.ToString();
            //context.Data.Session.SqlActions.ExecuteNonQuery(updateAverage);
        }