'Parses a location from wkt, returning wkt, lat, lon, bounding box and type.
For points, wkt may be None if lat and lon are provided; wkt will be generated.
For lines and polygons, the lat, lon returned represent the shape\'s centroid.
Centroid and bounding box will be None if Shapely is not available.'

@staticmethod
def parse_location(wkt, lon=None, lat=None):

    if (not wkt):
        if ((not (lon is not None)) and (lat is not None)):
            raise RuntimeError, 'Need    wkt    or    lon+lat    to    parse    a    location'
        wkt = ('POINT(%f    %f)' % (lon, lat))
        geom_type = GEOM_TYPES['point']
        bbox = (lon, lat, lon, lat)
    else:
        try:
            from shapely.wkt import loads as wkt_loads
            SHAPELY = True
        except:
            SHAPELY = False
        if SHAPELY:
            shape = wkt_loads(wkt)
            centroid = shape.centroid
            lat = centroid.y
            lon = centroid.x
            geom_type = GEOM_TYPES[shape.type.lower()]
            bbox = shape.bounds
        else:
            lat = None
            lon = None
            geom_type = GEOM_TYPES[wkt.split('(')[0].lower()]
            bbox = None
    res = {'wkt': wkt, 'lat': lat, 'lon': lon, 'gis_feature_type': geom_type}
    if bbox:
        (res['lon_min'], res['lat_min'], res['lon_max'], res['lat_max']) = bbox
    return res
