views.py 文件源码

python
阅读 19 收藏 0 点赞 0 评论 0

项目:georef 作者: rukayaj 项目源码 文件源码
def import_shp(request, shp_name):
    from django.contrib.gis.gdal import DataSource
    root = 'C:\\Users\\JohaadienR\\Documents\\Projects\\python-sites\\georef-data-sources\\planetgis\\'

    # Keep track of all the layers we are adding in
    layers = ['District Municipalities 2016.kml',
              'Local Municipalities 2016.kml',
              'Wards 2016.kml',
              'Main Places.kml',
              'Sub Places.kml']

    for layer_name in layers:
        ds = DataSource(root + layer_name)
        for item in ds[0]:
            # Get name and location from layer
            locality_name = item.get('Name')
            try:
                polygon = Polygon(item.geom.coords[1][0])
            except GEOSException:
                continue

            # Get/create the geographical position, locality name and importer profile
            gp, created = models.GeographicalPosition.objects.get_or_create(polygon=polygon, precision_m=0)
            ln, created = models.LocalityName.objects.get_or_create(locality_name=locality_name)
            au, created = models.Profile.objects.get_or_create(name='Surveyor General')

            # Get/create the georeference using the above
            models.GeoReference.objects.get_or_create(locality_name=ln, geographical_position=gp, author=au)
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号