Пример #1
0
def import_zip_from_shapefile(filename, zipcode):
    layer = layer_from_shapefile(filename, 0)
    importer = ZipImporter(layer, 'ZCTA5CE')
    try:
        importer.import_zip(zipcode)
    except:
        log_exception()
        return
Пример #2
0
def import_zip_from_shapefile(filename, zipcode):
    layer = layer_from_shapefile(filename, 0)
    importer = ZipImporter(layer, 'ZCTA5CE')
    try:
        importer.import_zip(zipcode)
    except:
        logger.exception('Zipcode import failed')
        return
Пример #3
0
def parse_args(optparser, argv):
    optparser.set_usage('usage: %prog [options] /path/to/shapefile')
    opts, args = optparser.parse_args(argv)

    if len(args) != 1:
        optparser.error('must give path to shapefile')

    layer = import_locations.layer_from_shapefile(args[0], opts.layer_id)

    return layer, opts
Пример #4
0
def parse_args(optparser, argv):
    optparser.set_usage('usage: %prog [options] /path/to/shapefile')
    opts, args = optparser.parse_args(argv)

    if len(args) != 1:
        optparser.error('must give path to shapefile')

    layer = import_locations.layer_from_shapefile(args[0], opts.layer_id)

    return layer, opts
Пример #5
0
 def clean(self):
     super(PickShapefileLayerForm, self).clean()
     if 'shapefile' in self.cleaned_data and 'layer' in self.cleaned_data:
         shapefile = os.path.abspath(self.cleaned_data['shapefile'])
         try:
             # We don't do anything with this yet, just verify that it's openable.
             x = import_locations.layer_from_shapefile(shapefile, self.cleaned_data['layer'])
             del(x)
         except Exception as e:
             self._errors['layer'] = self.error_class([u"Error loading the layer from the file. %s" % unicode(e)])
     return self.cleaned_data
Пример #6
0
def import_location(shapefile, layer_number, location_type, name, wkt, filter_bounds, display_order):
    # Passing WKT because background functions need all their args to
    # be json-serializable.
    try:
        layer = layer_from_shapefile(shapefile, layer_number)
        importer = LocationImporter(layer, location_type,
                                    filter_bounds=filter_bounds)
        geom = GEOSGeometry(wkt)
        importer.create_location(name, location_type, geom,
                                 display_order=display_order)
    except:
        logger.exception("Location import of %s failed" % name)
Пример #7
0
def import_locations_from_shapefile(shapefile, layer_number, location_type,
                                    name_field, filter_bounds):
    # Not in background since this should just quickly create a bunch of
    # import_location() jobs.
    try:
        layer = layer_from_shapefile(shapefile, layer_number)
        features = sorted(layer, key = lambda f: f.get(name_field))
        for i, feature in enumerate(features):
            name = feature.get(name_field)
            import_location(shapefile, layer_number, location_type, name, feature.geom.wkt, filter_bounds, display_order=i)
    except:
        logger.exception("Location import failed")
Пример #8
0
def parse_args(optparser, argv):
    optparser.set_usage('usage: %prog [options] /path/to/shapefile')
    optparser.remove_option('-n')
    optparser.add_option('-n', '--name-field', dest='name_field', default='ZCTA5CE',
                         help='field that contains the zipcode\'s name')
    opts, args = optparser.parse_args(argv)

    if len(args) != 1:
        optparser.error('must give path to shapefile')

    layer = import_locations.layer_from_shapefile(args[0], opts.layer_id)

    return layer, opts
Пример #9
0
 def clean(self):
     super(PickShapefileLayerForm, self).clean()
     if 'shapefile' in self.cleaned_data and 'layer' in self.cleaned_data:
         shapefile = os.path.abspath(self.cleaned_data['shapefile'])
         try:
             # We don't do anything with this yet, just verify that it's openable.
             x = import_locations.layer_from_shapefile(
                 shapefile, self.cleaned_data['layer'])
             del (x)
         except Exception as e:
             self._errors['layer'] = self.error_class([
                 u"Error loading the layer from the file. %s" % unicode(e)
             ])
     return self.cleaned_data
Пример #10
0
def parse_args(optparser, argv):
    optparser.set_usage("usage: %prog [options] /path/to/shapefile")
    optparser.remove_option("-n")
    optparser.add_option(
        "-n", "--name-field", dest="name_field", default="ZCTA5CE", help="field that contains the zipcode's name"
    )
    opts, args = optparser.parse_args(argv)

    if len(args) != 1:
        optparser.error("must give path to shapefile")

    layer = import_locations.layer_from_shapefile(args[0], opts.layer_id)

    return layer, opts
Пример #11
0
def import_location(shapefile, layer_number, location_type, name, wkt,
                    filter_bounds, display_order):
    # Passing WKT because background functions need all their args to
    # be json-serializable.
    try:
        layer = layer_from_shapefile(shapefile, layer_number)
        importer = LocationImporter(layer,
                                    location_type,
                                    filter_bounds=filter_bounds)
        geom = GEOSGeometry(wkt)
        importer.create_location(name,
                                 location_type,
                                 geom,
                                 display_order=display_order)
    except:
        logger.exception("Location import of %s failed" % name)
Пример #12
0
def import_locations_from_shapefile(shapefile, layer_number, location_type,
                                    name_field, filter_bounds):
    # Not in background since this should just quickly create a bunch of
    # import_location() jobs.
    try:
        layer = layer_from_shapefile(shapefile, layer_number)
        features = sorted(layer, key=lambda f: f.get(name_field))
        for i, feature in enumerate(features):
            name = feature.get(name_field)
            import_location(shapefile,
                            layer_number,
                            location_type,
                            name,
                            feature.geom.wkt,
                            filter_bounds,
                            display_order=i)
    except:
        logger.exception("Location import failed")
Пример #13
0
    def save(self):
        if not self.is_valid():
              return False

        shapefile = os.path.abspath(self.cleaned_data['shapefile'])
        layer = import_locations.layer_from_shapefile(shapefile, self.cleaned_data['layer'])
        location_type = self.cleaned_data['location_type']
        name_field = self.cleaned_data['name_field']

        # TODO: Run this as a background task
        importer = import_locations.LocationImporter(layer, location_type,
                                                     filter_bounds=True)
        if importer.save(name_field) > 0:
            # TODO: validate this directory!
            import shutil
            shutil.rmtree(os.path.dirname(shapefile))
            return True
        else:
            # TODO: would be nice to pass some errors back to page
            return False
Пример #14
0
    def save(self):
        if not self.is_valid():
              return False

        shapefile = os.path.abspath(self.cleaned_data['shapefile'])
        layer = import_locations.layer_from_shapefile(shapefile, self.cleaned_data['layer'])
        location_type = self.cleaned_data['location_type']
        name_field = self.cleaned_data['name_field']

        # TODO: Run this as a background task
        importer = import_locations.LocationImporter(layer, location_type,
                                                     filter_bounds=True)
        if importer.save(name_field) > 0:
            # TODO: validate this directory!
            import shutil
            shutil.rmtree(os.path.dirname(shapefile))
            return True
        else:
            # TODO: would be nice to pass some errors back to page
            return False