Example #1
0
    def testAppendPolygon(self):
        map = createMap(self.testdatadir)
        map.open(mode="a")

        parks, group = map.getLayerAndGroupByName("00_Parks")
        parks.open("a")

        # Add a new park
        park = (((16.1837837893217511,58.5911206585042237),(16.1834987729198474,58.5916966585245973),(16.1834275188193715,58.5918046585284173),(16.1833562647188955,58.5918586585303274),(16.1843538221255585,58.5919486585335108),(16.1843894491757965,58.5911746585061337),(16.1844963303265104,58.5911206585042237),(16.1837837893217511,58.5911206585042237)),)
        newpark = CellElementArea(park, objtype=13)

        newbbox = newpark.bboxrec.union(parks.bboxrec)
        newbbox = newbbox.buffer(parks.scale)
        
#        parks.setBBoxRec(newbbox)

        actual = Set([ce for ce in parks.getCellElements()])
        expected = actual.copy()
        
        newpark.discretizeGeometry(parks.getCell(1))
        parks.addCellElement(newpark)
        expected.add(newpark)

        actual = Set([ce for ce in parks.getCellElements()])

        # Test if the new parks exists in the layer object
        self.assertEqual(actual, expected)
        
        # Test if the new street was written to file
        parks.close()
        del parks
        del map

        map = createMap(self.testdatadir)
        map.open(mode="a")

        parks, group = map.getLayerAndGroupByName("00_Parks")
        parks.open("r")

#        actual = Set([ce.serialize(cell) for ce in parks.getCellElements()])
#        expected = Set([ce.serialize(cell) for ce in expected])
        actual = Set([ce for ce in parks.getCellElements()])
Example #2
0
    def addCoastLinePolygon(self, bbox = None):
        if self.coastline:
            layer, group = self.map.getLayerAndGroupByName(\
                self.map.mapnumstr + '_' + self.coastlayername )

            assert(layer.layertype == Layer.LayerTypePolygon)

            for polygon in self.coastline.polygons(bbox):
                try:
                    objtype = group.getObjtypeIndex(self.map.getLayerIndex(layer), 1)
                    cellelement = CellElementArea.fromfloat(layer, polygon, 
                                                            objtype=objtype)
                except GeometryError:
                    logging.warning('Improper polygon found: ' + str(coords))
                    return

                layer.addCellElement(cellelement)
        else:
            logging.warning("No coastline features found")
Example #3
0
    def add_element(self, statement, tags, coords):
      cm = self.charmap
      if statement.tag in ('polygon', 'polyline', 'point'):
        layer, group = self.map.getLayerAndGroupByName(\
            self.map.mapnumstr + '_' + statement.get('layer') )

        objtype = statement.get('objtype') or 1

        if statement.tag == 'polyline':
          assert(layer.layertype == Layer.LayerTypePolyline)
          if len(coords) < 2:
            return

          unk = None
          if self.routable:
              unk = 0
          cellelement = CellElementPolyline.fromfloat(layer, coords, \
                objtype=group.getObjtypeIndex(self.map.getLayerIndex(layer), objtype), unk=None)

          if self.routable:
              routingelements = statement.findall("routing")

              ra = RoutingAttributes()
              ra.segmentflags = 0
              ra.speedcat = 0
              cellelement.routingattributes = ra

              for routing in statement.findall("routing"):
                  for key, value in routing.items():
                      if key == 'oneway':
                          ra.bidirectional = value != 'on'
                      elif key == 'freeway':
                          ra.freeway = (value == 'on')
                      elif key == 'speedcat':
                          ra.speedcat = int(value)
                      elif key == 'segmenttype':
                          ra.segmenttype = int(value)

              if 'junction' in tags and self.tags['junction'] == 'roundabout':
                  ra.roundabout = True
                  ra.bidirectional = False

              if 'oneway' in tags and tags['oneway'] == 'yes':
                  ra.bidirectional = False

        elif statement.tag == 'polygon':
            try:
                objtype = group.getObjtypeIndex(self.map.getLayerIndex(layer), objtype)
                cellelement = CellElementArea.fromfloat(layer, (coords,), 
                                                        objtype=objtype)
            except GeometryError:
                logging.warning('Improper polygon found: ' + str(coords))
                return

        elif statement.tag == 'point':
          assert(layer.layertype == Layer.LayerTypePoint)
          cellelement = CellElementPoint.fromfloat(layer, coords[0],
                         objtype = group.getObjtypeIndex(self.map.getLayerIndex(layer), objtype))
        cellelementrefs = layer.addCellElement(cellelement)

        name = self._findname(statement, tags)

        if hasname(name):
            feature = FeatureNormal(name=cm.translate(name), 
                                    layerindex=self.map.getLayerIndex(layer),
                                    objtype=objtype,
                                    cellelementreflist=cellelementrefs)
            group.addFeature(feature)

      elif statement.tag == 'poi':
        poigroup = self.map.getPOIGroup()
        poilayer = self.map.getPOILayers()[0]

        category = statement.get('category')
        subcategory = statement.get('subcategory') or 'NOSUB1000'

        cat = poigroup.catman.getCategoryByName(category)
        subcat = cat.getSubCategoryByName(subcategory)

        poice = CellElementPOI.fromfloat(poilayer, coords[0], categoryid=cat.id, subcategoryid=subcat.id)

        name = self._findname(statement, tags)

        if hasname(name):
          attributes = []
          for a in statement.findall('attr'):
            if a.get('k') in tags:
              attributes.append(cm.translate(tags[a.get('k')]))
            elif a.text:
              attributes.append(cm.translate(a.text.encode))
            else:
              attributes.append('')

          feature = FeaturePOI(poilayer.addCellElement(poice), [cm.translate(name)] + attributes, cat.id, subcat.id)
          poigroup.addFeature(feature)
      elif statement.tag == 'coastline':
          if len(coords) < 2:
              return

          if self.coastline == None:
              self.coastline = coastline.CoastLine()

          self.coastline.add(coords)
          self.coastlayername = statement.get('layer')