예제 #1
0
        public void CallDirect()
        {
            Progress.Caption = "Simplificando geografías...";
            var ci = context.Data.Session.Query <GeographyItem>()
                     .ToList();

            Progress.Total = ci.Count;
            var    session = medea.context.Data.Session;
            string cad     = "";
            int    i       = 0;

            foreach (var item in ci)
            {
                i++;
                IGeometry geo = session.GetGeometry <GeographyItem>(item.Id.Value,
                                                                    x => x.Geometry);

                Simplifications.FillSimplifiedGeometries((Geometry)geo, item);

                string sql = "update geography_item set "
                             + "gei_geometry_r1 = " + InsertGenerator.GetValueEscaped(item.GeometryR1)
                             + ", gei_geometry_r2 = " + InsertGenerator.GetValueEscaped(item.GeometryR2)
                             + ", gei_geometry_r3 = " + InsertGenerator.GetValueEscaped(item.GeometryR3)
                             + ", gei_geometry_r4 = " + InsertGenerator.GetValueEscaped(item.GeometryR4)
                             + ", gei_geometry_r5 = " + InsertGenerator.GetValueEscaped(item.GeometryR5)
                             + ", gei_geometry_r6 = " + InsertGenerator.GetValueEscaped(item.GeometryR6)
                             + " where gei_id = " + item.Id.Value + ";";
                cad = cad + sql;
                try
                {
                    if (i % 20 == 0)
                    {
                        session.SqlActions.ExecuteNonQuery(cad);
                        cad = "";
                    }
                }
                catch (Exception e)
                {
                    Errors.Add("falló: " + item.Id.Value + " - " + e.ToString());
                }

                Progress.Increment();
            }

            session.SqlActions.ExecuteNonQuery(cad);
            cad = "";
        }
예제 #2
0
        void ProcessIds(List <GeographyItem> items, int i)
        {
            List <int> ids  = GetIds(items);
            var        geos = session.GetGeometries <GeographyItem>(ids, x => x.Geometry);
            string     cad  = "";

            foreach (var item in items)
            {
                Simplifications.FillSimplifiedGeometries((Geometry)geos[item.Id.Value], item);

                string sql = "update geography_item set "
                             + "gei_geometry_r1 = GeomFromText('" + item.GeometryR1.ToString() + "')"
                             + ", gei_geometry_r2 = GeomFromText('" + item.GeometryR2.ToString() + "')"
                             + ", gei_geometry_r3 = GeomFromText('" + item.GeometryR3.ToString() + "')"
                             + ", gei_geometry_r4 = GeomFromText('" + item.GeometryR4.ToString() + "')"
                             + ", gei_geometry_r5 = GeomFromText('" + item.GeometryR5.ToString() + "')"
                             + ", gei_geometry_r6 = GeomFromText('" + item.GeometryR6.ToString() + "')"
                             + " where gei_id = " + item.Id.Value + ";";
                cad = cad + sql;
            }
            System.IO.File.WriteAllText(Path.Combine(outFolder, i.ToString() + ".txt"), cad);
        }
예제 #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);
        }