Пример #1
0
def new_shapefile(shp, shx):
    """ Returns a new Shapefile instance
        Aguments:
            shp: Binary contents of the .shp file.
            shx: Binary contents of the .shx file.
    """
    md5 = hashlib.md5(shp).hexdigest().upper()
    model = Shapefile.get_by_key_name(md5)
    if model:
        return model
    else:
        model = Shapefile(md5)
        model.aws_bucket = AWS_SHP_BUCKET
        model.public = True
        numregions, extent, gmerc_extent = shp_info(shp, shx)
        model.n = numregions
        model.extent = extent
        model.gmerc_extent = gmerc_extent
        shp_url = s3_util.s3_upload(AWS_SHP_BUCKET, "public/%s.shp" % md5, shp, public=True, overwrite=True)
        shx_url = s3_util.s3_upload(AWS_SHP_BUCKET, "public/%s.shx" % md5, shx, public=True, overwrite=True)
        if shp_url and shx_url:
            model.shp_url = shp_url
            model.shx_url = shx_url
            model.put()
            return model
        else:
            return False
Пример #2
0
def new_shapefile_from_parts(md5, shx):
    model = Shapefile.get_by_key_name(md5)
    if model:
        return False
    shx_url = s3_util.s3_upload(AWS_SHP_BUCKET, "public/%s.shx" % md5, shx, public=True, overwrite=True)
    s3client = s3_multipart.AWS_S3(config.aws_accesskeyid, config.aws_accesskey)
    return s3client.initiate_multipart_upload("public/" + md5 + ".shp", bucketName="shapefiles")