Permalink
Browse files

sqlite working! (for points at least)

  • Loading branch information...
Calvin Metcalf
Calvin Metcalf committed Apr 11, 2013
1 parent bdda2c4 commit 492fa16c20f747c9bf1a1c9782423e5d12a16993
Showing with 32 additions and 24 deletions.
  1. BIN esri2open.tbx
  2. +24 −19 esri2open/esri2open.py
  3. +2 −2 esri2open/parseGeometry.py
  4. +5 −2 esri2open/parseRow.py
  5. +1 −1 esri2open/wkb.py
View
Binary file not shown.
View
@@ -46,34 +46,39 @@ def prepareSqlite(out,featureClass,fileType,includeGeometry):
elif shpType == "multipoint":
gType = 4
elif shpType == "polyline":
- gType = 5
+ gType = 2
elif shpType == "polygon":
- gType = 6
+ gType = 3
fields=listFields(featureClass)
fieldNames = []
+ fieldNames.append("OGC_FID INTEGER PRIMARY KEY")
+ if includeGeometry:
+ fieldNames.append("GEOMETRY blob")
for field in fields:
if (fields[field] != u'OID') and field.lower() not in ('shape_length','shape_area','shape.len','shape.length','shape_len','shape.area',shp.lower()):
fieldNames.append(parseFieldType(field,fields[field]))
- if includeGeometry:
- fieldNames.append("GEOMETRY blob")
- conn=Connection(out.name)
+
+ conn=Connection(out)
c=conn.cursor()
- c.execute("""CREATE TABLE spatial_ref_sys (
- srid INTEGER UNIQUE,
- auth_name TEXT,
- auth_srid INTEGER,
- srtext TEXT )""")
+ c.execute("""CREATE TABLE spatial_ref_sys(
+ srid INTEGER UNIQUE,
+ auth_name TEXT,
+ auth_srid TEXT,
+ srtext TEXT
+ )""")
c.execute("insert into spatial_ref_sys(srid ,auth_name ,auth_srid ,srtext) values(?,?,?,?)",(4326, u'EPSG', 4326, u'GEOGCS["WGS 84",DATUM["WGS_1984",SPHEROID["WGS 84",6378137,298.257223563,AUTHORITY["EPSG","7030"]],AUTHORITY["EPSG","6326"]],PRIMEM["Greenwich",0,AUTHORITY["EPSG","8901"]],UNIT["degree",0.0174532925199433,AUTHORITY["EPSG","9122"]],AUTHORITY["EPSG","4326"]]'))
- name = splitext(split(out.name)[1])[0]
+ name = splitext(split(out)[1])[0]
c.execute("""CREATE TABLE geometry_columns (
- f_table_name TEXT,
- f_geometry_column TEXT,
- geometry_type INTEGER,
- coord_dimension INTEGER,
- srid INTEGER,
- geometry_format TEXT )""")
- c.execute("""insert into geometry_columns( f_table_name, f_geometry_column, geometry_type, coord_dimension, srid,geometry_format) values(?,?,?,?,?,?)""",(name,"GEOMETRY",gType,2,4326))
+ f_table_name VARCHAR,
+ f_geometry_column VARCHAR,
+ geometry_type INTEGER,
+ coord_dimension INTEGER,
+ srid INTEGER,
+ geometry_format VARCHAR
+ )""")
+ c.execute("""insert into geometry_columns( f_table_name, f_geometry_column, geometry_type, coord_dimension, srid, geometry_format) values(?,?,?,?,?,?)""",(name,"GEOMETRY",gType,2,4326,"WKB"))
c.execute("create table {0}({1})".format(name,", ".join(fieldNames)))
+ conn.commit()
return [name,c,conn]
def prepareGeoJSON(outJSON,*args):
out = open(outJSON,"wb")
@@ -154,7 +159,7 @@ def toOpen(featureClass, outJSON, includeGeometry="geojson"):
if fileType=="geojson":
includeGeometry="geojson"
elif fileType=="sqlite":
- includeGeometry="well know binary"
+ includeGeometry="well known binary"
else:
includeGeometry=includeGeometry.lower()
#open up the file
@@ -193,8 +193,6 @@ def parseMultiPatch():
def getParseFunc(shpType, geo):
if geo == "none":
return False
- elif geo=="well known binary":
- return getWKBFunc(shpType)
else:
if shpType == "point":
fun = parsePoint
@@ -208,5 +206,7 @@ def getParseFunc(shpType, geo):
fun = parseMultiPatch
if geo=="geojson":
return fun
+ elif geo=="well known binary":
+ return getWKBFunc(shpType)
elif geo=="well known text":
return getWKTFunc(fun)
View
@@ -1,5 +1,5 @@
from utilities import listFields, getShp, getOID, statusMessage, parseProp, makeInter
-from arcpy import SpatialReference, SearchCursor
+from arcpy import SpatialReference, SearchCursor
from parseGeometry import getParseFunc
from json import dump
@@ -24,6 +24,7 @@ def __init__(self,outFile,featureClass,fileType,includeGeometry, first=True):
self.status = statusMessage(featureClass)
#define the correct geometry function if we're exporting geometry
self.parseGeo = getParseFunc(self.shpType,includeGeometry)
+ self.i=0
if fileType=="geojson":
self.parse = self.parseGeoJSON
elif fileType=="csv":
@@ -92,14 +93,16 @@ def parseSqlite(self,row):
#more messages
self.status.update()
fc=parseProp(row,self.fields, self.shp)
+ self.i=self.i+1
+ fc["OGC_FID"]=self.i
if self.parseGeo:
try:
fc["GEOMETRY"]=self.parseGeo(row.getValue(self.shp))
except:
return
keys = fc.keys()
values = fc.values()
- [name,c,conn]=outFile
+ [name,c,conn]=self.outFile
c.execute("""insert into {0}({1})
values({2})
""".format(name,", ".join(keys),makeInter(len(values))),values)
View
@@ -28,7 +28,7 @@ def linearRing(coordinates):
return out
def makePoint(c):
values = ["<BI",1,1]
- [ptrn,coords] = pts(c)
+ [ptrn,coords] = pts(c.getPart(0))
values[0]+=ptrn
values.extend(coords)
return Binary(pack(*values))

0 comments on commit 492fa16

Please sign in to comment.