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

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

            // initialize the node.
            var node = new Node();
            node.Latitude = -0.494497;
            node.Longitude = -24.119325;
            node.Tags = new TagsCollection();
            node.Tags.Add("type", "testnode");
            node.Visible = true;

            // save the node.
            node = apiInstance.NodeCreate(node);

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

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

            // get the new node id.
            long nodeId = node.Id.Value;

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

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

            // get the node.
            apiInstance.NodeDelete(node);

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

            // get the node.
            Node apiNode = apiInstance.NodeGet(node.Id.Value);
            Assert.IsNull(apiNode);
        }
示例#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;
                }
            }
        }