Example #1
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 #2
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')