public override void Call()
        {
            Progress.Caption = "Simplificando regiones...";
            var ci = context.Data.Session.Query <ClippingRegionItem>()
                     .ToList();

            Progress.Total = ci.Count;
            var session = medea.context.Data.Session;
            int i       = 1;

            foreach (var item in ci)
            {
                IGeometry geo = session.GetGeometry <ClippingRegionItem>(item.Id.Value,
                                                                         x => x.Geometry);
                i++;
                item.GeometryR1 = (Geometry)Simplifications.Simplify(geo, QualityEnum.High);
                if (item.GeometryR1.Coordinates.Length == 0)
                {
                    item.GeometryR1 = (Geometry)geo;
                }
                string sql = "update clipping_region_item set "
                             + "cli_geometry_r1 = " + InsertGenerator.GetValueEscaped(item.GeometryR1) +
                             " where cli_id = " + item.Id.Value;
                try
                {
                    session.SqlActions.ExecuteNonQuery(sql);
                }
                catch (Exception e)
                {
                    Errors.Add("falló: " + item.Id.Value + " - " + e.ToString());
                }

                Progress.Increment();
            }
        }
Пример #2
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();
        }