Beispiel #1
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();
        }
Beispiel #2
0
        private void SaveItems()
        {
            var session = context.Data.Session;

            Progress.Caption = "Guardando ítems de región por geografía";

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

            context.Data.Session.SqlActions.BulkInsert(sql, Progress);
            context.Data.Session.Flush();
            current.ClippingRegionItemGeographyItems.Clear();
        }
Beispiel #3
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);
        }