
 X                 @   sB   d  d l  m Z d  d l m Z m Z d d d d d d  Z d S)    )SpatialReference)DEFAULT_DB_ALIASconnectionsZEPSGNc       	      C   s  | s t  } n  t | } t | j d  s: t d   n  | j j sU t d   n  | j j   } t |  t	  s t	 |   }  n  |  j
 d k r t d   n  i |  j
 d 6| d 6| p |  j
 d 6|  j d	 6} d
 d   | j j   D } d | k r	|  j | d <n  d | k r+| p!|  j | d <n  y# | j j |  j d |  j
  Wn. | j k
 r~| j j |  j |   Yn Xd S)a  
    This function takes a GDAL SpatialReference system and adds its information
    to the `spatial_ref_sys` table of the spatial backend.  Doing this enables
    database-level spatial transformations for the backend.  Thus, this utility
    is useful for adding spatial reference systems not included by default with
    the backend:

    >>> from django.contrib.gis.utils import add_srs_entry
    >>> add_srs_entry(3857)

    Keyword Arguments:
     auth_name:
       This keyword may be customized with the value of the `auth_name` field.
       Defaults to 'EPSG'.

     auth_srid:
       This keyword may be customized with the value of the `auth_srid` field.
       Defaults to the SRID determined by GDAL.

     ref_sys_name:
       For SpatiaLite users only, sets the value of the `ref_sys_name` field.
       Defaults to the name determined by GDAL.

     database:
      The name of the database connection to use; the default is the value
      of `django.db.DEFAULT_DB_ALIAS` (at the time of this writing, its value
      is 'default').
    Zspatial_versionz=The `add_srs_entry` utility only works with spatial backends.z4This utility does not support your database backend.NzMSpatial reference requires an SRID to be compatible with the spatial backend.srid	auth_name	auth_sridZ	proj4textc             S   s   h  |  ] } | j   q S )name).0fr   r   J/home/ubuntu/projects/ifolica/build/django/django/contrib/gis/utils/srs.py	<setcomp>@   s   	 z add_srs_entry.<locals>.<setcomp>Zsrtextref_sys_name)r   r   hasattrops	ExceptionfeaturesZsupports_add_srs_entryZspatial_ref_sys
isinstancer   r   Zproj4Z_metaZ
get_fieldsZwktr	   ZobjectsZusinggetZDoesNotExistcreate)	Zsrsr   r   r   Zdatabase
connectionZSpatialRefSyskwargsZsrs_field_namesr   r   r   add_srs_entry   s2    	
#r   )Zdjango.contrib.gis.gdalr   Z	django.dbr   r   r   r   r   r   r   <module>   s   	