def testRemoveFeature(self): repo = self.getClonedRepo() repo.removefeatures(["parks/1"]) f = Feature(repo, geogig.WORK_HEAD, "parks/1") self.assertFalse(f.exists()) f = Feature(repo, geogig.STAGE_HEAD, "parks/1") self.assertFalse(f.exists())
def testBlame(self): feature = Feature(self.repo, geogig.HEAD, "parks/5") blame = feature.blame() self.assertEquals(8, len(blame)) attrs = feature.attributes for k,v in blame.iteritems(): self.assertTrue(v[0], attrs[k])
def testOsmImport(self): repoPath = self.getTempRepoPath() repo = Repository(repoPath, init = True) osmfile = os.path.join(os.path.dirname(__file__), "data", "osm", "ways.xml") repo.importosm(osmfile) feature = Feature(repo, geogig.WORK_HEAD, "way/31045880") self.assertTrue(feature.exists())
def testBlame(self): feature = Feature(self.repo, geogig.HEAD, "parks/5") blame = feature.blame() self.assertEquals(8, len(blame)) attrs = feature.attributes for k, v in blame.iteritems(): self.assertTrue(v[0], attrs[k])
def testModifyFeature(self): repo = self.getClonedRepo() attrs = Feature(repo, geogig.HEAD, "parks/1").attributes attrs["area"] = 1234.5 repo.insertfeature("parks/1", attrs) attrs = Feature(repo, geogig.WORK_HEAD, "parks/1").attributes self.assertEquals(1234.5, attrs["area"])
def testAddFeature(self): repo = self.getClonedRepo() attrs = Feature(repo, geogig.HEAD, "parks/1").attributes repo.insertfeature("parks/newfeature", attrs) newattrs = Feature(repo, geogig.WORK_HEAD, "parks/newfeature").attributes self.assertAlmostEqual(attrs["area"], newattrs["area"], 5)
def testOsmImportWithMappingFile(self): repoPath = self.getTempRepoPath() repo = Repository(repoPath, init = True) osmfile = os.path.join(os.path.dirname(__file__), "data", "osm", "ways.xml") mappingfile = os.path.join(os.path.dirname(__file__), "data", "osm", "mapping.json") repo.importosm(osmfile, False, mappingfile) feature = Feature(repo, geogig.WORK_HEAD, "onewaystreets/31045880") self.assertTrue(feature.exists())
def testDiff(self): feature = Feature(self.repo, geogig.HEAD, "parks/5") featureB = Feature(self.repo, geogig.HEAD + "~1", "parks/5") diffs = feature.diff(featureB) self.assertTrue(2, len(diffs)) areas = diffs["area"] self.assertEquals(15297.503295898438, areas[1]) self.assertEquals(15246.59765625, areas[0]) self.assertTrue("the_geom" in diffs)
def testFeatureType(self): feature = Feature(self.repo, geogig.HEAD, "parks/5") ftype = feature.featuretype() self.assertTrue("owner" in ftype) self.assertTrue("agency" in ftype) self.assertTrue("name" in ftype) self.assertTrue("parktype" in ftype) self.assertTrue("area" in ftype) self.assertTrue("perimeter" in ftype) self.assertTrue("the_geom" in ftype) self.assertEquals("MULTIPOLYGON EPSG:4326", ftype['the_geom'])
def testOsmImportWithMapping(self): mapping = OSMMapping() rule = OSMMappingRule("onewaystreets") rule.addfilter("oneway", "yes") rule.addfield("lit", "lit", geogig.TYPE_STRING) rule.addfield("geom", "the_geom", geogig.TYPE_LINESTRING) mapping.addrule(rule) repoPath = self.getTempRepoPath() repo = Repository(repoPath, init = True) osmfile = os.path.join(os.path.dirname(__file__), "data", "osm", "ways.xml") repo.importosm(osmfile, False, mapping) feature = Feature(repo, geogig.WORK_HEAD, "onewaystreets/31045880") self.assertTrue(feature.exists())
def testNoGeom(self): feature = Feature(self.repo, geogig.HEAD, "parks/5") allattrs = feature.attributes attrs = feature.attributesnogeom self.assertEquals(len(allattrs), len(attrs) + 1) self.assertTrue("owner" in attrs) self.assertTrue("agency" in attrs) self.assertTrue("name" in attrs) self.assertTrue("parktype" in attrs) self.assertTrue("area" in attrs) self.assertTrue("perimeter" in attrs) self.assertFalse("the_geom" in attrs)
def testAttributes(self): feature = Feature(self.repo, geogig.HEAD, "parks/1") data = feature.attributes self.assertEquals(8, len(data)) self.assertEquals("Public", data["usage"]) self.assertTrue("owner" in data) self.assertTrue("agency" in data) self.assertTrue("name" in data) self.assertTrue("parktype" in data) self.assertTrue("area" in data) self.assertTrue("perimeter" in data) self.assertTrue("the_geom" in data) self.assertTrue(isinstance(data["the_geom"], Geometry))
def testGeomFieldName(self): feature = Feature(self.repo, geogig.HEAD, "parks/5") name = feature.geomfieldname self.assertEquals("the_geom", name)
def testExists(self): feature = Feature(self.repo, geogig.HEAD, "parks/1") self.assertTrue(feature.exists()) feature = Feature(self.repo, geogig.HEAD, "wrong/path") self.assertFalse(feature.exists())
def testGeom(self): feature = Feature(self.repo, geogig.HEAD, "parks/5") geom = feature.geom self.assertTrue(isinstance(geom, Geometry))
repo = self.getClonedRepo() try: repo.merge("conflicted") self.fail() except GeoGigConflictException, e: pass conflicts = repo.conflicts() self.assertEquals(1, len(conflicts)) path = conflicts.keys()[0] self.assertTrue("parks/5", path) features = conflicts[path] origFeature = features[0] repo.solveconflict(path, origFeature.attributes) conflicts = repo.conflicts() self.assertEquals(0, len(conflicts)) feature = Feature(repo, geogig.WORK_HEAD, "parks/5") self.assertAlmostEqual(feature.attributes["area"], origFeature.attributes["area"], 5) def testSolveConflictOurs(self): repo = self.getClonedRepo() try: repo.merge("conflicted") self.fail() except GeoGigConflictException, e: pass conflicts = repo.conflicts() self.assertEquals(1, len(conflicts)) path = conflicts.keys()[0] self.assertTrue("parks/5", path) features = conflicts[path] oursFeature = features[1]