Beispiel #1
0
        public void APITestWayCreateGetDelete()
        {
            // intialize the connection.
            var apiInstance = new APIConnection("http://api06.dev.openstreetmap.org/",
                "osmsharp", "osmsharp");

            // open a changeset.
            apiInstance.ChangeSetOpen("Simple Way Creation Test");

            // initialize the way.
            var way = new Way();
            way.Tags = new TagsCollection();
            way.Tags.Add("type", "testway");
            way.Nodes = new List<long>();
            way.Visible = true;

            // initialize the nodes.
            var node = new Node();
            node.Latitude = -0.494497;
            node.Longitude = -24.119325;
            node.Tags = new TagsCollection();
            node.Tags.Add("type", "testnode1");
            node.Visible = true;
            node = apiInstance.NodeCreate(node);
            way.Nodes.Add(node.Id.Value);
            node = new Node();
            node.Latitude = -0.494497 + 0.0001f;
            node.Longitude = -24.119325 + 0.0001f;
            node.Tags = new TagsCollection();
            node.Tags.Add("type", "testnode2");
            node.Visible = true;
            node = apiInstance.NodeCreate(node);
            way.Nodes.Add(node.Id.Value);

            // save the way.
            way = apiInstance.WayCreate(way);

            // close the changeset.
            apiInstance.ChangeSetClose();

            // check if the id now has a value.
            Assert.IsTrue(way.Id.HasValue);

            // get the new way id.
            long wayId = way.Id.Value;

            // get the way again: a way can only be deleted using the correct changesetid and version.
            way = apiInstance.WayGet(way.Id.Value);

            // open new changeset.
            apiInstance.ChangeSetOpen("Simple Way Delete Test");

            // get the way.
            apiInstance.WayDelete(way);

            // close the current changeset.
            apiInstance.ChangeSetClose();

            // get the way.
            Way apiWay = apiInstance.WayGet(way.Id.Value);
            Assert.IsNull(apiWay);
        }
Beispiel #2
0
        public void APITestDeleteBoundingBox()
        {
            // intialize the connection.
            var apiInstance = new APIConnection("http://api06.dev.openstreetmap.org/",
                "osmsharp", "osmsharp");

            // get all objects in the box.
            var box = new GeoCoordinateBox(new GeoCoordinate(-0.494497, -24.119325),
                new GeoCoordinate(-0.494497, -24.119325));
            box = box.Resize(0.001f); // create a box around the usual test coordinates.
            List<OsmGeo> boxObjects = apiInstance.BoundingBoxGet(box);

            // delete all objects.
            apiInstance.ChangeSetOpen("delete test objects again");

            foreach (OsmGeo geoObject in boxObjects)
            {
                switch(geoObject.Type)
                {
                    case OsmGeoType.Relation:
                        apiInstance.RelationDelete(geoObject as Relation);
                        break;
                }
            }

            foreach (OsmGeo geoObject in boxObjects)
            {
                switch (geoObject.Type)
                {
                    case OsmGeoType.Way:
                        apiInstance.WayDelete(geoObject as Way);
                        break;
                }
            }

            foreach (OsmGeo geoObject in boxObjects)
            {
                switch (geoObject.Type)
                {
                    case OsmGeoType.Node:
                        apiInstance.NodeDelete(geoObject as Node);
                        break;
                }
            }
        }