|
|
|
@ -39,7 +39,7 @@ def get_spatial_reference(shapefile):
|
|
|
|
|
if not proj4:
|
|
|
|
|
#print 'Failed to convert prj of %s, giving up...' % shpfile
|
|
|
|
|
else:
|
|
|
|
|
#print 'Second try assuming ESRI wkt worked for %s!' % shpfile
|
|
|
|
|
#print 'Second try assuming ESRI wkt worked for %s!' % shpfile
|
|
|
|
|
"""
|
|
|
|
|
srs.from_esri = True
|
|
|
|
|
else:
|
|
|
|
@ -83,7 +83,7 @@ if os.path.isfile(prj_file):
|
|
|
|
|
if jres['codes']:
|
|
|
|
|
srid = int(jres['codes'][0]['code'])
|
|
|
|
|
except:
|
|
|
|
|
srid=None # ensure set back to 4326 whatever happens
|
|
|
|
|
srid=None # ensure set back to 4326 whatever happens
|
|
|
|
|
|
|
|
|
|
try:
|
|
|
|
|
# Try to detect the encoding
|
|
|
|
@ -101,17 +101,21 @@ try:
|
|
|
|
|
detector = UniversalDetector()
|
|
|
|
|
|
|
|
|
|
# 100 rows should be enough to figure encoding
|
|
|
|
|
# TODO: more broader and automated testing, allow
|
|
|
|
|
# TODO: more broader and automated testing, allow
|
|
|
|
|
# setting limit by command line param
|
|
|
|
|
for row in itertools.islice(db, 100):
|
|
|
|
|
# Feed detector with concatenated string fields
|
|
|
|
|
detector.feed( ''.join(row[fno] for fno in sfields) )
|
|
|
|
|
if detector.done: break
|
|
|
|
|
if detector.done: break
|
|
|
|
|
dbf.close()
|
|
|
|
|
detector.close()
|
|
|
|
|
encoding = detector.result["encoding"]
|
|
|
|
|
if encoding=="ascii":
|
|
|
|
|
encoding="LATIN1" # why not UTF8 here ?
|
|
|
|
|
# There's problems detecting LATIN1 encodings,
|
|
|
|
|
# it detects KOI8-R instead of LATIN1
|
|
|
|
|
if encoding=="KOI8-R":
|
|
|
|
|
encoding="LATIN1"
|
|
|
|
|
except Exception as err:
|
|
|
|
|
encoding="UTF8" # why not UTF8 here ?
|
|
|
|
|
#sys.stderr.write(repr(err)+'\n')
|
|
|
|
|