public void T04_InsertInDataSource()
        {
            PostGisProvider <Int64> prov = new PostGisProvider <Int64>(
                _geometryFactory, connectionString, "TestFeatureDataTable");

            GeometryLayer gl = new GeometryLayer("test", prov);

            gl.Select(new AllAttributesExpression());
            gl.Features.AcceptChanges();

            FeatureDataRow fdr = gl.Features.NewRow();

            fdr[0]       = 999;
            fdr.Geometry = gl.GeometryFactory.WktReader.Read("POINT (-2 13)");
            fdr[1]       = fdrLabel(fdr);
            gl.Features.AddRow(fdr);

            prov.Insert(gl.Features.GetChanges());

            //gl.SelectedFilter = new FeatureQueryExpression(
            //    new AttributeBinaryExpression(
            //        new PropertyNameExpression("OID"),
            //        BinaryOperator.Equals,
            //        (Int64)999));
            //Assert.AreEqual(5, gl.SelectedFeatures.TotalItemCount);

            fdr = gl.Features.Find(999);
            Assert.IsNotNull(fdr);
        }
示例#2
0
 public void NowySchemat(LayerSchema schemat)
 {
     _schemat  = schemat;
     _zakresy  = null;
     _atrybuty = null;
     mListView.Items.Clear();
 }
示例#3
0
        private void GeometryLayerTest()
        {
            //Bermuda Triangle is drawn on a GeometryLayer with TransformUpdate
            GeometryLayer transformLayer = new GeometryLayer(map) { UpdateMode = GeometryLayer.UpdateModes.TransformUpdate };
            transformLayer.Opacity = 0.5;
            map.Layers.Add(transformLayer);
            Polygon polygon = new Polygon();
            transformLayer.Add(polygon);
            polygon.Points = new ObservableCollection<Point> { new Point(-80.195, 25.775), new Point(-64.75, 32.303), new Point(-66.073, 18.44) };
            polygon.FillColor = Color.FromArgb(0x7F, 0xFF, 0x00, 0x00);
            System.Windows.Controls.ToolTipService.SetToolTip(polygon, "Bermuda Triangle");

            //Equator is drawn on a PanOnly GeometryLayer
            GeometryLayer panOnlyLayer = new GeometryLayer(map) { UpdateMode = GeometryLayer.UpdateModes.PanOnlyUpdate };
            panOnlyLayer.Opacity = 0.5;
            map.Layers.Add(panOnlyLayer);
            LineString line = new LineString();
            panOnlyLayer.Add(line);
            line.Points.Add(new Point(-180, 0));
            line.Points.Add(new Point(180, 0));
            line.LineThickness = 4;
            line.LineColor = Colors.White;
            System.Windows.Controls.ToolTipService.SetToolTip(line, "Equator");

            //Equator endpoints are drawn on an ElementUpdate Geometry Layer to test synching of layers
            GeometryLayer elementUpdateLayer = new GeometryLayer(map) { UpdateMode = GeometryLayer.UpdateModes.ElementUpdate };
            elementUpdateLayer.Opacity = 0.5;
            map.Layers.Add(elementUpdateLayer);
            elementUpdateLayer.Add(new PointBase { Point = new Point(-180, 0) });
            elementUpdateLayer.Add(new PointBase { X = 180, Y = 0 }); // Alternative syntax for setting a PointBase
        }
示例#4
0
        public ILayer Create(String layerName, String connectionInfo)
        {
            ShapeFileProvider shapeFileData  = new ShapeFileProvider(connectionInfo, _geometryFactory);
            GeometryLayer     shapeFileLayer = new GeometryLayer(layerName, shapeFileData);

            return(shapeFileLayer);
        }
        private static void setupShapefile(HttpContext context, Map m)
        {
            GeometryServices geometryServices = new GeometryServices();

            string[] layernames = new[]
            {
                "Countries",
                "Rivers"                          /*,
                                                   * "Cities"*/
            };

            foreach (string s in layernames)
            {
                ShapeFileProvider shapeFile =
                    new ShapeFileProvider(context.Server.MapPath(string.Format("~/App_Data/Shapefiles/{0}.shp", s)),
                                          geometryServices.DefaultGeometryFactory,
                                          geometryServices.CoordinateSystemFactory, false);
                shapeFile.IsSpatiallyIndexed = false;

                AppStateMonitoringFeatureProvider provider = new AppStateMonitoringFeatureProvider(shapeFile);

                GeoJsonGeometryStyle style = RandomStyle.RandomGeometryStyle();
                /* include GeoJson styles */
                style.IncludeAttributes            = false;
                style.IncludeBBox                  = true;
                style.PreProcessGeometries         = false;
                style.CoordinateNumberFormatString = "{0:F}";

                GeometryLayer geometryLayer = new GeometryLayer(s, style, provider);
                geometryLayer.Features.IsSpatiallyIndexed = false;
                m.AddLayer(geometryLayer);
                provider.Open();
            }
        }
示例#6
0
        internal static GeometryLayer CreateFeatureFeatureLayer(IGeometryFactory geoFactory,
                                                                Boolean includeGeometryCollections)
        {
            GeometryLayer layer = new GeometryLayer("TestFeatures",
                                                    CreateFeatureDatasource(geoFactory, includeGeometryCollections));

            return(layer);
        }
        public override void Wykonaj()
        {
            LayerSchema schemat = _form.Schemat;

            if (schemat == null)
            {
                ShowInfo("Przed importem atrybutów wybierz schemat bazy metadanych.");
                return;
            }

            GeometryLayer zakresy = _form.Zakresy;

            if (zakresy == null)
            {
                ShowInfo("Przed importem atrybutów wczytaj zasięgi.");
                return;
            }

            if (_dialog.ShowDialog(_form) != DialogResult.OK)
            {
                return;
            }

            try
            {
                schemat.Validate();

                AttributeLayer atrybuty = new AttributeLayer(schemat, _dialog.FileName);

                string ext = Path.GetExtension(_dialog.FileName);

                switch (ext.ToLower())
                {
                case ".txt":
                    atrybuty.ImportujTekstowy();
                    break;

                case ".xls":
                    atrybuty.ImportujExcel();
                    break;

                default:
                    break;
                }

                _form.ImportujAtrybuty(atrybuty);
                ShowInfo(atrybuty.ToString() + "\nPrzypisane atrybuty: " + zakresy.Count);
            }
            catch (Exception ex)
            {
                _form.ImportujAtrybuty(null);
                ShowError(ex.Message);
            }

            _form.AktualizujTytul();
        }
示例#8
0
文件: ToDXF.cs 项目: lulzzz/Nucleus
        /// <summary>
        /// Convert a Nucleus layer to a netDXF one
        /// </summary>
        /// <param name="layer"></param>
        /// <returns></returns>
        public static Layer Convert(GeometryLayer layer)
        {
            var result = new Layer(layer.Name);

            if (layer.Brush != null)
            {
                result.Color = Convert(layer.Brush.BaseColour);
            }
            result.IsVisible = layer.Visible;
            return(result);
        }
        public void T02_CreateGeometryLayerFromPostGis()
        {
            PostGisProvider <Int64> prov = new PostGisProvider <Int64>(
                _geometryFactory, connectionString, "TestFeatureDataTable");

            GeometryLayer gl = new GeometryLayer("test", prov);

            Assert.IsNotNull(gl);
            Assert.AreEqual("test", gl.LayerName);
            Assert.AreEqual(prov.Srid, gl.Srid);
        }
示例#10
0
        public void MapExtentsReflectTheUnderlyingLayersCorrectlyWhenUsingAddLayer()
        {
            Map map = new Map(_factories.GeoFactory);

            GeometryLayer layer = new GeometryLayer("Geom layer",
                                                    DataSourceHelper.CreateGeometryDatasource(_factories.GeoFactory));

            map.AddLayer(layer);
            IExtents box = map.Extents;

            Assert.Equal(_factories.GeoFactory.CreateExtents2D(0, 0, 120, 100), box);
        }
        public void T03_SomeSelects()
        {
            PostGisProvider <Int64> prov = new PostGisProvider <Int64>(
                _geometryFactory, connectionString, "TestFeatureDataTable");
            GeometryLayer gl = new GeometryLayer("test", prov);

            gl.Select(new AllAttributesExpression());
            gl.Features.AcceptChanges();
            Assert.AreEqual(4, gl.Features.FeatureCount);
            Assert.AreEqual(_geometryFactory.CreateExtents2D(0, -3, 15, 20), gl.Features.Extents);

            gl = new GeometryLayer(prov);
            gl.Select(
                new SpatialBinaryExpression(
                    new ExtentsExpression(prov.GeometryFactory.CreateExtents2D(-1, -1, 1, 1)),
                    SpatialOperation.Contains,
                    new ThisExpression())
                );
            Assert.AreEqual(1, gl.Features.Rows.Count);

            gl = new GeometryLayer(prov);
            gl.Select(
                new SpatialBinaryExpression(
                    new GeometryExpression(prov.GeometryFactory.WktReader.Read(("POLYGON((-1 -1, 0 1, 1 -1, -1 -1))"))),
                    SpatialOperation.Contains,
                    new ThisExpression())
                );
            //SELECT testfeaturedatatable.poid,testfeaturedatatable.label,ST_AsBinary(xgeometryx)::bytea AS xgeometryx FROM public.testfeaturedatatable   WHERE  ( ST_Contains( ST_GeomFromWKB(:iparam0, -1), xgeometryx ))
            //SELECT testfeaturedatatable.poid,testfeaturedatatable.label,ST_AsBinary(xgeometryx)::bytea AS xgeometryx FROM public.testfeaturedatatable   WHERE  ( ST_Contains( ST_GeomFromText('POLYGON((-1 -1, 0 1, 1 -1, -1 -1))', -1), xgeometryx ))
            Assert.AreEqual(1, gl.Features.Rows.Count);

            gl = new GeometryLayer(prov);
            gl.Select(
                new SpatialBinaryExpression(
                    new GeometryExpression(
                        prov.GeometryFactory.WktReader.Read(("POLYGON((-1 -1, -1 1, 0 1, 0 -1, -1 -1))"))),
                    SpatialOperation.Touches,
                    new ThisExpression())
                );
            Assert.AreEqual(1, gl.Features.Rows.Count);

            //gl = new GeometryLayer(prov);
            //gl.Select(
            //    new SpatialBinaryExpression(
            //        new ThisExpression(),
            //        SpatialOperation.Within,
            //        new GeometryExpression(prov.GeometryFactory.WktReader.Read("POLYGON((-1 -1, 0 1, 1 -1, -1 -1))")))
            //        );
            //Assert.AreEqual(0, gl.Features.Rows.TotalItemCount);
        }
示例#12
0
        private void AddLayer()
        {
            using (ChooseDataSource choose = new ChooseDataSource())
            {
                if (choose.ShowDialog() == DialogResult.OK)
                {
                    IFeatureProvider prov = choose.Provider;
                    string           name = choose.ProviderName;

                    workQueue.AddWorkItem(
                        string.Format("Loading Datasource {0}", name),
                        delegate
                    {
                        GeometryLayer lyr =
                            new GeometryLayer(
                                name,
                                prov);
                        lyr.Features.IsSpatiallyIndexed = false;
                        prov.Open();


                        InvokeIfRequired(new Action(delegate
                        {
                            if (Map.Layers.Count == 0)
                            {
                                if (lyr.SpatialReference != null)
                                {
                                    Map.SpatialReference = lyr.SpatialReference;
                                }
                            }

                            Map.Layers.Insert(0, lyr);

                            lyr.Style = RandomStyle.RandomGeometryStyle();
                            //lyr.Style = setGeometryStyle(lyr);

                            if (Map.Layers.Count == 1)
                            {
                                mapViewControl1.Map = Map;

                                layersView1.Map = Map;
                                MapView.ZoomToExtents();
                            }
                        }));
                    }, EnableDisableCommandsRequiringLayers
                        ,
                        delegate(Exception ex) { MessageBox.Show(string.Format("An error occured\n{0}\n{1}", ex.Message, ex.StackTrace)); });
                }
            }
        }
示例#13
0
        /// <summary>
        /// Bake all geometry in the specified layer into Rhino on an
        /// equivalent layer
        /// </summary>
        /// <param name="layer"></param>
        public static void BakeAll(GeometryLayer layer)
        {
            int layerID = GetLayerID(layer.Name);

            if (layer.Brush != null)
            {
                SetLayerColour(layerID, layer.Brush.BaseColour);
            }
            foreach (VertexGeometry vG in layer)
            {
                Guid gID = Bake(vG);
                SetObjectLayer(gID, layerID);
            }
        }
示例#14
0
        /// <summary>
        /// Read data from an ESRI Shapefile and convert it into a .NUCLEUS geometry layer
        /// </summary>
        /// <param name="filePath">The filepath of the shapefile</param>
        /// <returns></returns>
        public GeometryLayer ReadShapefile(FilePath filePath)
        {
            var result    = new GeometryLayer(filePath.FileName);
            var shapeFile = DotSpatial.Data.Shapefile.OpenFile(filePath);

            foreach (IFeature feature in shapeFile.Features)
            {
                VertexGeometry vGeo = ToNucleus.Convert(feature);
                if (vGeo != null)
                {
                    result.Add(vGeo);
                }
            }
            return(result);
        }
        public void T03_MultipleSelects()
        {
            SpatiaLite2Provider prov = new SpatiaLite2Provider(
                _geometryFactory, @"Data Source=test.sqlite", "TestFeatureDataTable");
            GeometryLayer gl = new GeometryLayer("test", prov);

            gl.Select(new AllAttributesExpression());
            gl.Features.AcceptChanges();
            Assert.AreEqual(4, gl.Features.FeatureCount);
            Assert.AreEqual(_geometryFactory.CreateExtents2D(0, -3, 15, 20), gl.Features.Extents);

            gl = new GeometryLayer(prov);
            gl.Select(
                new SpatialBinaryExpression(
                    new ExtentsExpression(prov.GeometryFactory.CreateExtents2D(-1, -1, 1, 1)),
                    SpatialOperation.Contains,
                    new ThisExpression())
                );
            Assert.AreEqual(1, gl.Features.Rows.Count);

            gl = new GeometryLayer(prov);
            gl.Select(
                new SpatialBinaryExpression(
                    new GeometryExpression(prov.GeometryFactory.WktReader.Read(("POLYGON((-1 -1, 0 1, 1 1, -1 -1))"))),
                    SpatialOperation.Contains,
                    new ThisExpression())
                );
            Assert.AreEqual(1, gl.Features.Rows.Count);

            gl = new GeometryLayer(prov);
            gl.Select(
                new SpatialBinaryExpression(
                    new GeometryExpression(prov.GeometryFactory.WktReader.Read(("POLYGON((-1 -1, -1 1, 0 1, 0 -1, -1 -1))"))),
                    SpatialOperation.Touches,
                    new ThisExpression())
                );
            Assert.AreEqual(1, gl.Features.Rows.Count, 1);

            gl = new GeometryLayer(prov);
            gl.Select(
                new SpatialBinaryExpression(
                    new ThisExpression(),
                    SpatialOperation.Within,
                    new GeometryExpression(prov.GeometryFactory.WktReader.Read(("POLYGON((-1 -1, 0 1, 1 1, -1 -1))"))))
                );
            Assert.AreEqual(0, gl.Features.Rows.Count);
        }
        public override void Wykonaj()
        {
            LayerSchema _schemat = _form.Schemat;

            if (_schemat == null)
            {
                ShowInfo("Przed importem zasięgów wybierz schemat bazy metadanych.");
                return;
            }

            if (_dialog.ShowDialog(_form) != DialogResult.OK)
            {
                return;
            }

            try
            {
                _schemat.Validate();
                GeometryLayer zakresy = new GeometryLayer(_schemat, _dialog.FileName);

                string ext = Path.GetExtension(_dialog.FileName);

                switch (ext.ToLower())
                {
                case ".txt":
                    zakresy.ImportujPhoto();
                    break;

                default:
                    zakresy.ImportujOgr();
                    break;
                }

                _form.ImportujZakresy(zakresy);

                ShowInfo(zakresy.ToString());
            }
            catch (Exception ex)
            {
                _form.ImportujZakresy(null);
                ShowError(ex.Message);
            }

            _form.AktualizujTytul();
        }
        public override void Wykonaj()
        {
            LayerSchema _schemat = _form.Schemat;

            if (_schemat == null)
            {
                ShowInfo("Przed importem punktów wybierz schemat bazy metadanych.");
                return;
            }

            if (_dialog.ShowDialog(_form) != DialogResult.OK)
            {
                return;
            }

            try
            {
                _schemat.Validate();
                GeometryLayer  zakresy  = new GeometryLayer(_schemat, _dialog.FileName);
                AttributeLayer atrybuty = null;

                string ext = Path.GetExtension(_dialog.FileName);

                switch (ext.ToLower())
                {
                case ".xls":
                    atrybuty = zakresy.ImportujPunkty(_schemat);
                    break;

                default:
                    break;
                }

                _form.ImportujZintegrowaneZakresy(zakresy, atrybuty);

                ShowInfo(zakresy.ToString() + "\n" + atrybuty.ToString());
            }
            catch (Exception ex)
            {
                _form.ImportujZintegrowaneZakresy(null, null);
                ShowError(ex.Message);
            }

            _form.AktualizujTytul();
        }
        public void T99_GeometryFromBinary()
        {
            PostGisProvider <Int64> prov = new PostGisProvider <Int64>(
                _geometryFactory, connectionString, "TestFeatureDataTable");
            GeometryLayer gl = new GeometryLayer("test", prov);

            gl.Select(new AllAttributesExpression());
            using (NpgsqlConnection cn = new NpgsqlConnection(connectionString))
            {
                cn.Open();
                NpgsqlCommand cm = new NpgsqlCommand(
                    "SELECT ST_SRID( ST_GeomFromWKB(:p0::bytea, -1) )", cn);
                NpgsqlParameter par = new NpgsqlParameter(":p0", DbType.Binary);
                par.Value = prov.GeometryFactory.WktReader.Read("POLYGON((-1 -1, 0 1, 1 -1, -1 -1))").AsBinary();
                cm.Parameters.Add(par);
                Debug.Write(cm.ExecuteScalar());
            }
        }
示例#19
0
        private void GeometryAnchorTest()
        {
            var point = new Point(0, 0);

            if (anchorTestLayer == null)
            {
                anchorTestLayer = new GeometryLayer(map) { ID = "RESULTSLAYER", UpdateMode = GeometryLayer.UpdateModes.ElementUpdate };
                styleArrow = (Application.Current.Resources["PushPinArrowStyle"]) as Style;
                map.Layers.Add(anchorTestLayer);
            }

            //Add an arrow pin whose another point is an anchor of 0.5, 1.0;
            PointBase arrowPin = new PointBase { Point = point, Style = styleArrow };
            anchorTestLayer.Add(arrowPin);

            //Add a another point with the default style which has an anchor of 0.5, 0.5;
            PointBase defaultPin = new PointBase { Point = point };
            anchorTestLayer.Add(defaultPin);
        }
示例#20
0
        public void GetMap_GeometryProvider_ReturnImage()
        {
            MockRepository mocks = new MockRepository();

            TestPresenter2D mapPresenter = createPresenter(mocks, 400, 200);

            Map map = mapPresenter.Map;

            GeometryLayer vLayer = new GeometryLayer("Geom layer", DataSourceHelper.CreateGeometryDatasource(_factories.GeoFactory));

            vLayer.Style.Outline       = new StylePen(StyleColor.Red, 2f);
            vLayer.Style.EnableOutline = true;
            vLayer.Style.Line          = new StylePen(StyleColor.Green, 2f);
            vLayer.Style.Fill          = new SolidStyleBrush(StyleColor.Yellow);
            map.AddLayer(vLayer);

            GeometryLayer vLayer2 = new GeometryLayer("Geom layer 2", vLayer.DataSource);
            Stream        data    = Assembly.GetAssembly(typeof(Map))
                                    .GetManifestResourceStream("SharpMap.Styles.DefaultSymbol.png");

            vLayer2.Style.Symbol          = new Symbol2D(data, new Size2D(16, 16));
            vLayer2.Style.Symbol.Offset   = new Point2D(3, 4);
            vLayer2.Style.Symbol.Rotation = 45;
            vLayer2.Style.Symbol.Scale(0.4f);
            map.AddLayer(vLayer2);

            GeometryLayer vLayer3 = new GeometryLayer("Geom layer 3", vLayer.DataSource);

            vLayer3.Style.Symbol.Offset   = new Point2D(3, 4);
            vLayer3.Style.Symbol.Rotation = 45;
            map.AddLayer(vLayer3);

            GeometryLayer vLayer4 = new GeometryLayer("Geom layer 4", vLayer.DataSource);

            vLayer4.Style.Symbol.Offset = new Point2D(3, 4);
            vLayer2.Style.Symbol.Scale(0.4f);
            map.AddLayer(vLayer4);

            mapPresenter.ZoomToExtents();

            map.Dispose();
        }
示例#21
0
        public override void Wykonaj()
        {
            LayerSchema schemat = _form.Schemat;

            if (schemat == null)
            {
                ShowInfo("Przed importem atrybutów wybierz schemat bazy metadanych.");
                return;
            }

            GeometryLayer zakresy = _form.Zakresy;

            if (zakresy == null)
            {
                ShowInfo("Przed importem atrybutów wczytaj zasięgi.");
                return;
            }

            if (_dialog.ShowDialog(_form) != DialogResult.OK)
            {
                return;
            }

            try
            {
                schemat.Validate();

                AttributeLayer atrybuty = new AttributeLayer(schemat, _dialog.FileName);
                atrybuty.ImportujExcelKolumnowo();

                _form.ImportujAtrybutyKolumnowo(atrybuty);

                ShowInfo(atrybuty.ToString() + "\nPrzypisane atrybuty: " + zakresy.Count);
            }
            catch (Exception ex)
            {
                _form.ImportujAtrybutyKolumnowo(null);
                ShowError(ex.Message);
            }

            _form.AktualizujTytul();
        }
示例#22
0
        public void LayerCachingTest()
        {
            IGeometryFactory geoFactory = _factories.GeoFactory;
            GeometryLayer    layer1     = DataSourceHelper.CreateFeatureFeatureLayer(geoFactory);
            GeometryLayer    layer2     = DataSourceHelper.CreateFeatureFeatureLayer(geoFactory);

            IExtents box1 = geoFactory.CreateExtents2D(0, 0, 10, 10);
            IExtents box2 = geoFactory.CreateExtents2D(35, 25, 45, 35);

            layer1.AsyncQuery = false;
            // Do query

            layer2.AsyncQuery = false;
            // Do query

            Assert.True(layer1.Features.Extents.Contains(box2), "Test validity check");
            // features intersecting box1 must have extents that contain box2

            // Do query
        }
示例#23
0
        private ILayer generateFeatureLayer()
        {
            VectorStyle style = new VectorStyle();
            String      layerName;

            switch (_rnd.Next(3))
            {
            case 0:
            {
                KeyValuePair <String, Symbol2D> symbolEntry = getSymbolEntry(_rnd.Next(_symbolTable.Count));
                style.Symbol = symbolEntry.Value;
                layerName    = symbolEntry.Key;
            }
            break;

            case 1:
            {
                KeyValuePair <String, StyleColor> colorEntry = getColorEntry(_rnd.Next(_colorTable.Count));
                style.Line = new StylePen(colorEntry.Value, _rnd.NextDouble() * 3);
                layerName  = String.Format("{0} lines", colorEntry.Key);
            }
            break;

            case 2:
            {
                KeyValuePair <String, StyleColor> colorEntry = getColorEntry(_rnd.Next(_colorTable.Count));
                style.Fill = new SolidStyleBrush(colorEntry.Value);
                layerName  = String.Format("{0} squares", colorEntry.Key);
            }
            break;

            default:
                throw new InvalidOperationException();
            }

            GeometryLayer layer = new GeometryLayer(layerName, generateFeatureDataSource());

            return(layer);
        }
示例#24
0
        public void ImportujZakresy(GeometryLayer zakresy)
        {
            _atrybuty = null;
            _zakresy  = zakresy;
            mListView.Items.Clear();

            if (zakresy == null)
            {
                return;
            }

            foreach (GeometryFeature gf in _zakresy.Features)
            {
                string[] pola = new string[_schemat.Fields.Count];

                int index = mListView.Columns.IndexOfKey(_schemat.AttribKey);
                pola[index] = gf.Value;
                ListViewItem item = new ListViewItem(pola);
                item.Tag = gf;

                mListView.Items.Add(item);
            }
        }
        public void T05_DeleteFromDataSource()
        {
            PostGisProvider <Int64> prov = new PostGisProvider <Int64>(
                _geometryFactory, connectionString, "TestFeatureDataTable");

            GeometryLayer gl = new GeometryLayer(prov);

            gl.Select(new SpatialBinaryExpression(
                          new ExtentsExpression(prov.GetExtents()), SpatialOperation.Contains, new ThisExpression()));
            gl.Features.AcceptChanges();

            //gl.Features.RemoveRow(gl.Features[4]);
            FeatureDataRow fdr = gl.Features.Find(999);

            fdr.Delete();
            //prov.Delete(gl.Features.GetChanges(DataRowState.Deleted));
            gl.Features.AcceptChanges();

            gl = new GeometryLayer(prov);
            gl.Select(new SpatialBinaryExpression(
                          new ExtentsExpression(prov.GetExtents()), SpatialOperation.Contains, new ThisExpression()));
            gl.Features.AcceptChanges();
            //Assert.AreEqual(4, gl.Features.Rows.TotalItemCount);
        }
        public void T05_DeleteFromDataSource()
        {
            SpatiaLite2Provider prov = new SpatiaLite2Provider(
                _geometryFactory, @"Data Source=test.sqlite", "TestFeatureDataTable");

            GeometryLayer gl = new GeometryLayer(prov);

            gl.Select(new SpatialBinaryExpression(
                          new ExtentsExpression(prov.GetExtents()), SpatialOperation.Contains, new ThisExpression()));
            gl.Features.AcceptChanges();

            //gl.Features.RemoveRow(gl.Features[4]);
            FeatureDataRow fdr = gl.Features.Find(999);

            fdr.Delete();
            //prov.Delete(gl.Features.GetChanges(DataRowState.Deleted));
            gl.Features.AcceptChanges();

            gl = new GeometryLayer(prov);
            gl.Select(new SpatialBinaryExpression(
                          new ExtentsExpression(prov.GetExtents()), SpatialOperation.Contains, new ThisExpression()));
            gl.Features.AcceptChanges();
            //Assert.AreEqual(4, gl.Features.Rows.Count);
        }
示例#27
0
        private void AddPolygon_Click(object sender, RoutedEventArgs e)
        {
            ////Sample Polygon added to the map
            //ConfigShapeLayer();
            //var points = new List<Point> {new Point(0, 0), new Point(20, 0), new Point(20, 20), new Point(0, 20)};
            //var polygon = new Polygon {Points = points};
            //shapeLayer.Add(polygon);

            if (shapeLayer == null)
            {
                shapeLayer = new GeometryLayer(MapInstance) { ID = "POLYGONLAYER" };
                shapeLayer.UpdateMode = GeometryLayer.UpdateModes.PanOnlyUpdate; //Old Method
                //shapeLayer.UpdateMode = GeometryLayer.UpdateModes.TransformUpdate;
                shapeLayer.Opacity = 0.4;

                MapInstance.Layers.Insert(1, shapeLayer);
            }

            var points = new ObservableCollection<Point> { new Point(0, 0), new Point(20, 0), new Point(20, 20), new Point(0, 20) };
            //var polygon = new Polygon(shapeLayer) { Points = points };
            var polygon = new Polygon() { Points = points };
            polygon.FillColor = Colors.Green;
            shapeLayer.Add(polygon);

            var linePoints = new ObservableCollection<Point> { new Point(-88, 42), new Point(-75, 39) };
            //LineString line = new LineString(shapeLayer) { Points = linePoints };
            LineString line = new LineString() { Points = linePoints };
            line.LineThickness = 4;
            line.LineColor = Colors.White;
            shapeLayer.Add(line);

            //Add points at each end of the
            shapeLayer.Add(new PointBase { Point = new Point(-88, 42) });
            shapeLayer.Add(new PointBase { Point = new Point(-75, 39) });
            //new PointBase(shapeLayer) { Point = new Point(-88, 42) };
            //new PointBase(shapeLayer) { Point = new Point(-75, 39) };
        }
示例#28
0
 public void ImportujZintegrowaneZakresy(GeometryLayer zakresy, AttributeLayer atrybuty)
 {
     ImportujZakresy(zakresy);
     ImportujAtrybuty(atrybuty);
 }
示例#29
0
        private void MouseUp(Map map, MouseButtonEventArgs args)
        {
            if (isMouseDown && !isMouseDrag)
            {
                Point coord = map.CoordHelper.PixelToGeo(args.GetPosition(map));

                if (shapeLayer == null)
                {
                    ///TODO: RoadWarrior, to demo this, create a subclass of ShapeLayer for specialty behavior.
                    //shapeLayer = new ShapeLayer(map)
                    //{
                    //    ID = "PROTOTYPE",
                    //    InfoBoxOffset = new Point(-20, 0),
                    //    InfoBoxContentProvider = (shape, callback) =>
                    //    {
                    //        var pin = (PointBase)shape;
                    //        var point = pin.Point;
                    //        var description = string.Format("Created point at {0:N6}, {1:N6}", point.X, point.Y);
                    //        callback(description);
                    //    }
                    //};
                    shapeLayer = new GeometryLayer(map){ID = "PROTOTYPE"};

                    map.Layers.Add(shapeLayer);

                    //create the info box
                    //infoBox = new InfoBox();
                    //shapeLayer.Shapes.Add(infoBox);
                    //infoBox.HideInfoBox();  // initially hide the infobox
                }

                // create the pushpin if the "A" key is held down;  We don't want this behaviour with normal clicks.

                if (_IsAKeyDown)
                {
                    //var pushpin = new Pushpin(shapeLayer) { Point = coord };
                    var pushpin = new Pushpin() { Point = coord };
                    //pushpin.MouseLeftButtonDown += OnPushpinMouseDown;
                    shapeLayer.Add(pushpin);

                    args.Handled = true;
                }
            }

            isMouseDown = false;
            isMouseDrag = false;
        }
        public override void Wykonaj()
        {
            LayerSchema _schemat = _form.Schemat;

            if (_schemat == null)
            {
                ShowInfo("Przed eksportem metadanych wybierz schemat bazy metadanych.");
                return;
            }

            GeometryLayer _zakresy = _form.Zakresy;

            if (_zakresy == null)
            {
                ShowInfo("Przed eksportem metadanych wczytaj zasięgi.");
                return;
            }

            AttributeLayer _atrybuty = _form.Atrybuty;

            if (_atrybuty == null)
            {
                ShowInfo("Przed eksportem metadanych wczytaj atrybuty.");
                return;
            }

            if (Directory.Exists(Settings.Default.RecentCatalog))
            {
                _dialog.SelectedPath = Settings.Default.RecentCatalog;
            }

            if (_dialog.ShowDialog(_form) != DialogResult.OK)
            {
                return;
            }

            Settings.Default.RecentCatalog = _dialog.SelectedPath;
            Settings.Default.Save();

            try
            {
                LayerCatalog catalog = new LayerCatalog(_dialog.SelectedPath, _schemat);

                if (catalog.LayerExists(_zakresy.LayerName))
                {
                    ShowError("Zbiór metadanych " + _zakresy.LayerName + " już istnieje.");
                }
                else
                {
                    MetadataLayer layer = null;

                    switch (_zakresy.Typ)
                    {
                    case TypZakresu.Poligonowy:
                        layer = catalog.CreatePolygonLayer(_zakresy.LayerName);
                        break;

                    case TypZakresu.Punktowy:
                        layer = catalog.CreatePointLayer(_zakresy.LayerName);
                        break;
                    }

                    _form.EksportujMetadane(layer);
                    layer.Dispose();

                    ShowInfo("Eksport zakończony.");
                }

                catalog.Dispose();
            }
            catch (Exception ex)
            {
                ShowError(ex.Message);
            }

            _form.AktualizujTytul();
        }
示例#31
0
 private void AddPinToLayer(Point location, string styleKey, GeometryLayer layer)
 {
     var pin = new DevPin() { Point = location, Style = (Application.Current.Resources[styleKey] as Style) };
     layer.Add(pin);
     Canvas.SetZIndex(pin, GetNextRandomZ());
 }
示例#32
0
        public override void OnApplyTemplate()
        {
            base.OnApplyTemplate();

            // Test IsDesignTime, to help display control in blend correctly
            if (HtmlPage.IsEnabled)
            {
                if (DrawLayer == null)
                {
                    _DrawLayerGrid = (Grid)GetTemplateChild("PART_DrawControlLayers");
                    DrawLayer = new GeometryLayer(_Map) { UpdateMode = GeometryLayer.UpdateModes.TransformUpdate };
                    DrawLayers.Add(DrawLayer);
                }
                if (EditableDevPinLayer == null)
                {
                    EditableDevPinLayer = new GeometryLayer(_Map) { ID = "EDITABLEDEVPINLAYER" };
                    EditableDevPinLayer.UpdateMode = GeometryLayer.UpdateModes.ElementUpdate;
                    DrawLayers.Add(EditableDevPinLayer);
                }
                if (LinesPointsLayer == null)
                {
                    LinesPointsLayer = new GeometryLayer(_Map) { ID = "SHAPELAYER" };
                    LinesPointsLayer.UpdateMode = GeometryLayer.UpdateModes.ElementUpdate;
                    DrawLayers.Add(LinesPointsLayer);
                }
                if (PolygonsPointsLayer == null)
                {
                    PolygonsPointsLayer = new GeometryLayer(_Map) { ID = "POLYGONSPOINTSLAYER" };
                    PolygonsPointsLayer.UpdateMode = GeometryLayer.UpdateModes.ElementUpdate;
                    DrawLayers.Add(PolygonsPointsLayer);
                }
                if (DrawPointLayer == null)
                {
                    DrawPointLayer = new GeometryLayer(_Map) { ID = "DRAWPOINTLAYER" };
                    DrawPointLayer.UpdateMode = GeometryLayer.UpdateModes.ElementUpdate;
                    DrawLayers.Add(DrawPointLayer);
                }
                if (DrawDirectedPinLayer == null)
                {
                    DrawDirectedPinLayer = new GeometryLayer(_Map) { ID = "DRAWDIRECTEDPINLAYER" };
                    DrawDirectedPinLayer.UpdateMode = GeometryLayer.UpdateModes.ElementUpdate;
                    DrawLayers.Add(DrawDirectedPinLayer);
                }
                if (ImagePinLayer == null)
                {
                    ImagePinLayer = new GeometryLayer(_Map) { ID = "DRAWIMAGEPINLAYER" };
                    ImagePinLayer.UpdateMode = GeometryLayer.UpdateModes.ElementUpdate;
                    DrawLayers.Add(ImagePinLayer);
                }

                //Create event handlers for standard MouseControl behavior.

                //  MapInstance.Events.MapMouseEnter += Events_MapMouseEnter;
                MapInstance.Events.MapMouseLeave += Events_MapMouseLeave;
                MapInstance.Events.MapDoubleClick += Events_MapDoubleClick;
                MapInstance.Events.MapMouseDown += Events_MapMouseDown;
                MapInstance.Events.MapMouseMove += Events_MapMouseMove;
                MapInstance.Events.MapMouseDrag += Events_MapMouseDrag;
                MapInstance.Events.MapMouseUp += Events_MapMouseUp;
                MapInstance.Events.MapDragBehavourChanged += Events_MapDragBehavourChanged;
            }
        }
示例#33
0
        private void AddLocationPin(GeocodeResult result)
        {
            var point = new Point(result.Locations[0].Longitude, result.Locations[0].Latitude);

            if (resultsShapeLayer == null)
            {
                resultsShapeLayer = new GeometryLayer(MapInstance) { ID = "RESULTSLAYER" };
                Style style = (Application.Current.Resources["PushPinArrowStyle"]) as Style;
                resultsShapeLayer.ItemsStyle = style;
                MapInstance.Layers.Add(resultsShapeLayer);
            }
            else
            {
                resultsShapeLayer.Clear();
            }

            MapInstance.SetViewCenter(point, 12);

            //Add an arrow pin whose another point is an anchor of 0.5, 1.0;
            PointBase arrowPin = new PointBase { Point = point};
            resultsShapeLayer.Add(arrowPin);
        }
        private static void setupMsSqlSpatial(Map m)
        {
            string[] layernames = new[]
            { "Rivers",
              "Countries"

              /*,
               * "Cities"*/
            };

            string sridstr = SridMap.DefaultInstance.Process(4326, "");

            foreach (string lyrname in layernames)
            {
                string tbl = lyrname;


                AppStateMonitoringFeatureProvider provider = new AppStateMonitoringFeatureProvider(
                    new MsSqlSpatialProvider(
                        new GeometryServices()[sridstr],
                        ConfigurationManager.ConnectionStrings["db"].ConnectionString,
                        "st",
                        "dbo",
                        tbl,
                        "oid",
                        "Geometry")
                {
                    DefaultProviderProperties
                        = new ProviderPropertiesExpression(
                              new ProviderPropertyExpression[]
                    {
                        new WithNoLockExpression(true)
                    })
                });


                GeoJsonGeometryStyle style = new GeoJsonGeometryStyle();

                switch (tbl)
                {
                case "Rivers":
                {
                    StyleBrush brush = new SolidStyleBrush(StyleColor.Blue);
                    StylePen   pen   = new StylePen(brush, 1);
                    style.Enabled       = true;
                    style.EnableOutline = true;
                    style.Line          = pen;
                    style.Fill          = brush;
                    break;
                }

                case "Countries":
                {
                    StyleBrush brush = new SolidStyleBrush(new StyleColor(0, 0, 0, 255));
                    StylePen   pen   = new StylePen(brush, 2);
                    style.Enabled       = true;
                    style.EnableOutline = true;
                    style.Line          = pen;
                    style.Fill          = new SolidStyleBrush(StyleColor.Green);

                    break;
                }

                default:
                {
                    style            = RandomStyle.RandomGeometryStyle();
                    style.MaxVisible = 100000;
                    break;
                }
                }


                /* include GeoJson styles */
                style.IncludeAttributes            = false;
                style.IncludeBBox                  = true;
                style.PreProcessGeometries         = false;
                style.CoordinateNumberFormatString = "{0:F}";
                GeometryLayer layer = new GeometryLayer(tbl, style, provider);
                layer.Features.IsSpatiallyIndexed = false;
                layer.AddProperty(AppStateMonitoringFeatureLayerProperties.AppStateMonitor, provider.Monitor);
                m.AddLayer(layer);
            }
        }
示例#35
0
        private void AddRoute_Click(object sender, RoutedEventArgs e)
        {
            var locations = new List<Point>();

            foreach (GeocodeResult p in GeocodeRoutePoints.Items)
            {
                locations.Add(new Point {X = p.Locations[0].Longitude, Y = p.Locations[0].Latitude});
            }

            RouteService.GetDirections(locations, (o, ev) =>
                                                      {
                                                          RouteResult result = ((RouteResultArgs) ev).Result;
                                                          var points = new ObservableCollection <Point>();
                                                          foreach (Location loc in result.RoutePath.Points)
                                                          {
                                                              points.Add(new Point(loc.Longitude, loc.Latitude));
                                                          }
                                                          if (routeLayer == null)
                                                          {
                                                              routeLayer = new GeometryLayer(MapInstance) {ID = "ROUTELAYER"};
                                                              routeLayer.UpdateMode = GeometryLayer.UpdateModes.TransformUpdate;
                                                              MapInstance.Layers.Add(routeLayer);
                                                          }
                                                          else
                                                          {
                                                              routeLayer.Clear();
                                                          }
                                                          routeLayer.Add(new LineString {Points = points, LineThickness = 2, LineColor = Colors.Blue});
                                                          //new LineString(routeLayer) { Points = points, LineThickness = 2, LineColor = Colors.Blue };
                                                          //add pins for the locations specified
                                                          foreach (Point point in locations)
                                                          {
                                                              routeLayer.Add(new Pushpin{Point = point});
                                                              //new Pushpin(routeLayer) { Point = point };
                                                          }
                                                      });

            ClearSearchFields();

            VisualStateManager.GoToState(this, "CloseGeoRouteListBox", true);
            VisualStateManager.GoToState(this, "CloseGeoFindListBox", true);
        }
示例#36
0
        private void ConfigureDevPins()
        {
            if (_DevPinsConfigured == false)
            {
                if (devPinLayer == null)
                {
                    devPinLayer = new GeometryLayer(MapInstance) { ID = "DEVPINLAYER" };
                    devPinLayer.UpdateMode = GeometryLayer.UpdateModes.ElementUpdate;
                    MapInstance.Layers.Add(devPinLayer);
                }

                AddPinToLayer(new Point(-77.0365, 38.897), "RoadWarriorPinStyle", devPinLayer);
                AddPinToLayer(new Point(153.430172, -27.998868), "NoobiePinStyle", devPinLayer);
                AddPinToLayer(new Point(153.025, -27.470), "SoulPinStyle", devPinLayer);
                AddPinToLayer(new Point(-83.437448, 42.352317), "SMBeckerPinStyle", devPinLayer);
                AddPinToLayer(new Point(-77.0467, 38.33096), "AquasealPinStyle", devPinLayer);

                _DevPinsConfigured = true;
            }
        }