In [12]:
from rockfish2.utils.loaders import get_example_file
from rockfish2.navigation.p190 import P190
In [13]:
p190 = P190(filename=get_example_file('MGL1407MCS15.TEST.p190'), database='temp.p190.sqlite')
In [14]:
p190._init_spatial()
In [15]:
sql = """DROP TABLE IF EXISTS test_geom"""
p190.execute(sql)
sql = """CREATE TABLE test_geom (
id INTEGER NOT NULL
PRIMARY KEY AUTOINCREMENT,
name TEXT NOT NULL,
easting DOUBLE NOT NULL,
northing DOUBLE NOT NULL);"""
p190.execute(sql)
sql = """SELECT AddGeometryColumn('test_geom', 'geom',
4326, 'POINT', 'XY');"""
p190.execute(sql)
sql = """
INSERT INTO test_geom
(id, name, easting, northing, geom)
VALUES (NULL, 'first point', 1.01, 2.02,
GeomFromText('POINT(1.01 2.02)', 4326));"""
p190.execute(sql)
p190.commit()
In [28]:
# add new point in two steps
sql = """INSERT INTO test_geom
(id, name, easting, northing)
VALUES (NULL, 'second point', 2., 3.)"""
print sql
p190.execute(sql)
p190.commit()
In [35]:
sql = "SELECT easting, northing, rowid FROM test_geom"
dat = p190.read_sql(sql)
i = 1
sql = "UPDATE test_geom SET geom=GeomFromText('POINT(? ?)', 4326) WHERE id=?"
print sql
p190.executemany(sql, np.asarray(dat))
p190.commit()
In [5]:
# add geometry column to coordinates table
p190.EPSG = 32619
sql = "SELECT addGeometryColumn('{:}', 'geom', {:}, 'POINT', 'XY');"\
.format(p190.COORDINATE_TABLE, p190.EPSG)
p190.execute(sql)
Out[5]:
In [6]:
# add data
sql = "INSERT INTO {:}(geom) VALUES (GeomFromText('POINT(? ?)', {:}))"\
.format(p190.COORDINATE_TABLE, p190.EPSG)
dat = p190.read_sql('SELECT easting, northing FROM {:}'.format(p190.COORDINATE_TABLE))
p190.executemany(sql, np.asarray(dat))
In [ ]:
sql = "INSERT INTO coordinates(geom) VALUES (GeomFromText('POINT(63520.2 3600513.)', 32619)) WHERE rowid=1"
p190.execute(sql)
In [ ]:
dat[0:1]
In [ ]: