コード例 #1
0
 def spawn_folder(Class, data_folder, random_length=None):
     parent_folder = Class.get_parent_folder(data_folder)
     return (
         make_unique_folder(parent_folder, length=random_length)
         if random_length
         else make_enumerated_folder(parent_folder)
     )
コード例 #2
0
ファイル: macros.py プロジェクト: salah93/geotable
def _get_source_folder(source_path_or_url, temporary_folder, file_extensions):
    if isdir(source_path_or_url):
        return source_path_or_url
    if source_path_or_url.startswith(
            'http://') or source_path_or_url.startswith('https://'):
        source_name = basename(source_path_or_url).strip()
        source_path = join(temporary_folder, source_name.lower())
        urlretrieve(source_path_or_url, source_path)
    else:
        source_path = source_path_or_url
    source_extension = splitext(source_path)[1]
    target_folder = make_unique_folder(temporary_folder)
    if source_extension not in file_extensions:
        try:
            return uncompress(source_path, target_folder)
        except BadFormat:
            pass
        for extension in ARCHIVE_EXTENSIONS:
            try:
                link_path = link_safely(
                    make_unique_path(temporary_folder, extension), source_path)
                return uncompress(link_path, target_folder)
            except BadArchive:
                pass
    raise GeoTableError(source_path)
コード例 #3
0
ファイル: serve.py プロジェクト: crosscompute/crosscompute
 def prepare_arguments(self, tool_definition, raw_arguments):
     draft_folder = make_unique_folder(join(
         self.data_folder, 'drafts', Result._plural), length=16)
     try:
         result_arguments = self.collect_arguments(
             tool_definition, raw_arguments, draft_folder)
     except DataParseError as e:
         raise HTTPBadRequest(e.message_by_name)
     result = self.spawn_result()
     result.arguments = self.migrate_arguments(
         result_arguments, result.get_source_folder(self.data_folder))
     remove_safely(draft_folder)
     return result
コード例 #4
0
ファイル: serve.py プロジェクト: cclauss/crosscompute
 def prepare_arguments(self, tool_definition, raw_arguments):
     draft_folder = make_unique_folder(join(self.data_folder, 'drafts',
                                            Result._plural),
                                       length=16)
     try:
         result_arguments = self.collect_arguments(tool_definition,
                                                   raw_arguments,
                                                   draft_folder)
     except DataParseError as e:
         raise HTTPBadRequest(e.message_by_name)
     result = self.spawn_result()
     result.arguments = corral_arguments(
         result.get_source_folder(self.data_folder), result_arguments,
         move_path)
     remove_safely(draft_folder)
     return result
コード例 #5
0
 def spawn_folder(Class, data_folder, id_length=None, owner_id=None):
     user_folder = Class.get_user_folder(data_folder, owner_id)
     return make_unique_folder(
         user_folder, length=id_length,
     ) if id_length else make_enumerated_folder(user_folder)
コード例 #6
0
import geopy
import geotable
import numpy as np
from geotable.projections import get_transform_shapely_geometry
from invisibleroads_macros.disk import make_unique_folder, uncompress
from os.path import exists, join, splitext
from shapely.geometry import Point
from urllib.request import urlretrieve

geometry_columns = ['geometry_layer', 'geometry_proj4', 'geometry_object']
target_folder = make_unique_folder('/tmp')

g = geopy.GoogleV3('AIzaSyDNqc0tWzXHx_wIp1w75-XTcCk4BSphB5w').geocode
location = g('Greensboro, NC')
p = Point(location.longitude, location.latitude)
proj4s = open('proj4s.txt').read().splitlines()
target_proj4 = geotable.LONGITUDE_LATITUDE_PROJ4

archive_url = ('https://egriddata.org/sites/default/files/'
               'GSO_RNM_GIS_Network.zip')
archive_path = '/tmp/greensboro-synthetic-network.zip'
archive_folder = splitext(archive_path)[0]
if not exists(archive_path):
    urlretrieve(archive_url, archive_path)
if not exists(archive_folder):
    archive_folder = uncompress(archive_path)
source_folder = join(archive_folder, 'GSO_RNM_GIS_Network', 'Rural')

source_path = join(source_folder, 'Line_N.shp')
t = line_table = geotable.load(source_path)