#NEWLINE# def add_boundaries_for_layer( self , config , layer , bset , database ) : #NEWLINE# #INDENT# geometry_field = Boundary . _meta . get_field_by_name ( GEOMETRY_COLUMN ) [ 0 ] #NEWLINE# SpatialRefSys = connections [ database ] . ops . spatial_ref_sys ( ) #NEWLINE# db_srs = SpatialRefSys . objects . using ( database ) . get ( srid = geometry_field . srid ) . srs #NEWLINE# if ( ( 'srid' in config ) and config [ 'srid' ] ) : #NEWLINE# #INDENT# layer_srs = SpatialRefSys . objects . get ( srid = config [ 'srid' ] ) . srs #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# layer_srs = layer . srs #NEWLINE# #UNINDENT# simplification = config . get ( 'simplification' , 0.0001 ) #NEWLINE# transformer = CoordTransform ( layer_srs , db_srs ) #NEWLINE# for feature in layer : #NEWLINE# #INDENT# log . debug ( ( 'Processing boundary %s' % feature ) ) #NEWLINE# geometry = self . polygon_to_multipolygon ( feature . geom ) #NEWLINE# geometry . transform ( transformer ) #NEWLINE# simple_geometry = geometry . geos . simplify ( simplification , preserve_topology = True ) #NEWLINE# simple_geometry = self . polygon_to_multipolygon ( simple_geometry . ogr ) #NEWLINE# metadata = { #NEWLINE# #INDENT# #NEWLINE# #UNINDENT# } #NEWLINE# for field in layer . fields : #NEWLINE# #INDENT# if ( config [ 'encoding' ] != '' ) : #NEWLINE# #INDENT# try : #NEWLINE# #INDENT# metadata [ field ] = feature . get ( field ) . decode ( config [ 'encoding' ] ) #NEWLINE# #UNINDENT# except AttributeError : #NEWLINE# #INDENT# metadata [ field ] = feature . get ( field ) #NEWLINE# #UNINDENT# #UNINDENT# else : #NEWLINE# #INDENT# metadata [ field ] = feature . get ( field ) #NEWLINE# #UNINDENT# #UNINDENT# external_id = config [ 'ider' ] ( feature ) #NEWLINE# feature_name = config [ 'namer' ] ( feature ) #NEWLINE# if ( config [ 'encoding' ] != '' ) : #NEWLINE# #INDENT# external_id = external_id . decode ( config [ 'encoding' ] ) #NEWLINE# feature_name = feature_name . decode ( config [ 'encoding' ] ) #NEWLINE# #UNINDENT# if config [ 'kind_first' ] : #NEWLINE# #INDENT# display_name = ( '%s %s' % ( config [ 'singular' ] , feature_name ) ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# display_name = ( '%s %s' % ( feature_name , config [ 'singular' ] ) ) #NEWLINE# #UNINDENT# Boundary . objects . create ( set = bset , kind = config [ 'singular' ] , external_id = external_id , name = feature_name , display_name = metadata , metadata = metadata , shape = geometry . wkt , simple_shape = simple_geometry . wkt , centroid = geometry . geos . centroid )