Skip to content

Commit

Permalink
fixed unicode-ascii issue with degree symbol, found and merged Robs m…
Browse files Browse the repository at this point in the history
…issing beardist code, tweaked to get beardist to work. Improved survey edit form; various DB changes
  • Loading branch information
gavin committed Mar 9, 2013
1 parent 8a41cd8 commit e8b2722
Show file tree
Hide file tree
Showing 7 changed files with 79 additions and 18 deletions.
Binary file added DMS2DD.ods
Binary file not shown.
9 changes: 5 additions & 4 deletions PyQt4Dialogs.py
Original file line number Diff line number Diff line change
Expand Up @@ -791,7 +791,7 @@ def __init__(self, db, beardistSql, beaconSql, beaconSchema, parent = None):
self.surveyPlan = None
self.referenceBeacon = None
self.beardistChain = []
self.beardistStr = "%s" + chr(176) + " and %sm from %s to %s"
self.beardistStr = "%s" + u"\u00B0" + " and %sm from %s to %s"
# initialize initial step
self.initItemSurveyPlan()

Expand Down Expand Up @@ -863,7 +863,7 @@ def initItemReferenceBeacon(self, forward=True):
self.lnedt_ref.setCompleter(completer)
# reset variables associated with items
self.referenceBeacon = None
# check direction from whence it came
# check direction whence it came
if forward:
# check if survey plan number has a pre-defined reference beacon
if self.surveyPlan in self.auto["SURVEYPLAN"]:
Expand Down Expand Up @@ -992,7 +992,7 @@ def isLastAnchorLink(self, index):
beacon_ref = self.beardistChain[index][0][2]
# check if reference beacon is used
if beacon_ref != self.referenceBeacon: return False
# count number of reference beacon occurances
# count number of reference beacon occurrences
count = 0
for link in self.beardistChain:
beacon_from = link[0][2]
Expand Down Expand Up @@ -1030,6 +1030,7 @@ def updateBearDistChainDependants(self):
self.auto["FROMBEACON"] = [self.referenceBeacon]
# populate dependants
for link in self.beardistChain:
#QMessageBox.information(self,QString(','.join(link[0][:4])))
self.lst_chain.addItem(QString(self.beardistStr %tuple(link[0][:4])))
self.auto["FROMBEACON"].append(link[0][3])
self.auto["FROMBEACON"].sort()
Expand Down Expand Up @@ -1067,7 +1068,7 @@ def editLink(self):
values = dlg.getReturn()
# check if anything was changed
if values == self.beardistChain[index][0]: return
# check if refernce beacon can be found
# check if reference beacon can be found
if not self.canFindReferenceBeacon(self.beardistChain[index][0][3]):
QMessageBox.information(None, "", "oops")
# recursively update beacon names if changed
Expand Down
2 changes: 1 addition & 1 deletion database_changes.sql
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ $BODY$
LANGUAGE plpgsql VOLATILE
COST 100;
--
CREATE OR REPLACE FUNCTION public.BearDistInsert(
CREATE OR REPLACE FUNCTION public.beardistinsert(
arg_plan_no character varying(20),
arg_bearing double precision,
arg_distance double precision,
Expand Down
18 changes: 13 additions & 5 deletions database_changes_v2.sql
Original file line number Diff line number Diff line change
Expand Up @@ -124,10 +124,11 @@ WITH (
--int4(row_number() OVER (ORDER BY vl.parcel_id)) AS gid,
--drop view parcels;
CREATE OR REPLACE VIEW parcels AS
SELECT parcel.*, round(st_area(parcel.the_geom)::numeric,3)::double precision AS comp_area,description.official_area,description.parcel_number, description.block, description.scheme,
description.file_number,description.allocation,description.owner,
'<a href="http://192.168.10.12/geoserver/'||description.deeds_file
||'" target="blank_">'||description.deeds_file||'</a>' AS deeds_file FROM
SELECT parcel.*, round(st_area(parcel.the_geom)::numeric,3)::double precision AS comp_area,
description.official_area,description.parcel_number, description.block, description.serial_no,
description.scheme, description.file_number,description.allocation,description.owner,
'<a href="http://192.168.10.12/geoserver/' || description.deeds_file ||'" target="blank_">'||
description.deeds_file||'</a>' AS deeds_file FROM
(SELECT int4(vl.parcel_id) as parcel_id,
st_makepolygon(st_addpoint(st_makeline(vl.the_geom),st_startpoint(st_makeline(vl.the_geom))))::geometry(Polygon,26331) AS the_geom
FROM ( SELECT pd.id, pd.parcel_id, pd.beacon, pd.sequence, b.the_geom
Expand All @@ -137,7 +138,7 @@ CREATE OR REPLACE VIEW parcels AS
GROUP BY vl.parcel_id
HAVING st_npoints(st_collect(vl.the_geom)) > 1) AS parcel
INNER JOIN
(SELECT p.parcel_id,p.local_govt || p.prop_type || p.plot_sn AS parcel_number, p.allocation,p.block,p.official_area,
(SELECT p.parcel_id,p.local_govt || p.prop_type || p.parcel_id AS parcel_number, p.allocation,p.block,p.plot_sn AS serial_no,p.official_area,
s.scheme_name AS scheme,p.file_number,d.grantee AS owner,p.deeds_file
FROM parcel_lookup p LEFT JOIN deeds d ON p.file_number=d.fileno LEFT JOIN schemes s ON p.scheme = s.id) AS description
USING (parcel_id);
Expand Down Expand Up @@ -237,3 +238,10 @@ ALTER TABLE parcel_lookup ADD COLUMN official_area double precision;

ALTER TABLE survey ADD FOREIGN KEY (ref_beacon) REFERENCES beacons (beacon) ON UPDATE NO ACTION ON DELETE NO ACTION;

--convert plot_sn from integer to character_varying so ids like '7A' can be added

drop view parcels;

alter table parcel_lookup alter column plot_sn type character varying;

CREATE VIEW parcels ...
12 changes: 9 additions & 3 deletions settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@
"EDIT":"SELECT {fields} FROM beacons WHERE gid = %s;",
"DELETE":"DELETE FROM beacons WHERE gid = %s;",
"INSERT":"INSERT INTO beacons({fields}) VALUES ({values}) RETURNING gid;",
"UPDATE":"UPDATE beacons SET {set} WHERE {where};"
"UPDATE":"UPDATE beacons SET {set} WHERE {where};",
"BEARDIST":"SELECT CASE WHEN count(*) = 0 THEN FALSE ELSE TRUE END FROM beardist WHERE beacon_to = (SELECT beacon FROM beacons WHERE gid = %s);"
}
}
DATABASE_LAYERS["PARCELS"] = {
Expand Down Expand Up @@ -68,6 +69,11 @@
"AUTO_SURVEYPLAN":"SELECT array_agg(plan_no) FROM survey;",
"AUTO_REFERENCEBEACON":"SELECT array_agg(beacon) FROM beacons WHERE beacon NOT IN (SELECT beacon_to FROM beardist WHERE beacon_to NOT IN (SELECT ref_beacon FROM survey));",
"EXIST_REFERENCEBEACON":"SELECT ref_beacon FROM survey where plan_no = %s;",
"EXIST_BEARDISTCHAINS":"SELECT bearing, distance, beacon_from, beacon_to FROM beardist WHERE plan_no = %s",
"INDEX_REFERENCEBEACON":"SELECT i.column_index::integer FROM (SELECT row_number() over(ORDER BY c.ordinal_position) -1 as column_index, c.column_name FROM information_schema.columns c WHERE c.table_name = 'beacons' AND c.column_name NOT IN ('the_geom', 'gid') ORDER BY c.ordinal_position) as i WHERE i.column_name = 'beacon';"
"EXIST_BEARDISTCHAINS":"SELECT bd.bearing, bd.distance, bd.beacon_from, bd.beacon_to, b.location, b.name FROM beardist bd INNER JOIN beacons b ON bd.beacon_to = b.beacon WHERE bd.plan_no = %s;",
"INDEX_REFERENCEBEACON":"SELECT i.column_index::integer FROM (SELECT row_number() over(ORDER BY c.ordinal_position) -1 as column_index, c.column_name FROM information_schema.columns c WHERE c.table_name = 'beacons' AND c.column_name NOT IN ('geom', 'gid') ORDER BY c.ordinal_position) as i WHERE i.column_name = 'beacon';",
"IS_SURVEYPLAN":"SELECT CASE WHEN COUNT(*) <> 0 THEN TRUE ELSE FALSE END FROM survey WHERE plan_no = %s;",
"INSERT_SURVEYPLAN":"INSERT INTO survey(plan_no, ref_beacon) VALUES(%s, %s);",
"UPDATE_LINK":"SELECT beardistupdate(%s, %s, %s, %s, %s, %s, %s, %s);",
"DELETE_LINK":"DELETE FROM beacons WHERE beacon = %s;",
"INSERT_LINK":"SELECT beardistinsert(%s, %s, %s, %s, %s, %s, %s);"
}
52 changes: 49 additions & 3 deletions sml_surveyor.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ def initGui(self):
if not(self.manageDatabase()): raise Exception("Unspecied database parameters")
# find layers
self.getLayers()
self.showLayers()
# add app toolbar
self.createAppToolBar()

Expand Down Expand Up @@ -127,6 +128,7 @@ def showLayers(self):
for n,l in self.layers.items():
self.iface.legendInterface().setLayerVisible(l, True)
l.loadNamedStyle(os.path.join(self.plugin_dir, "styles", "%s.qml" %(n.lower(),)))
self.iface.legendInterface().refreshLayerSymbology(l)

def dropLayers(self):
""" Drop added postgis layers
Expand Down Expand Up @@ -174,11 +176,47 @@ def manageDatabase(self):
def manageBearDist(self):
"""
"""
dlg = dlg_FormBearDist(self.db, settings.DATABASE_OTHER_SQL, settings.DATABASE_LAYERS["BEACONS"]["SQL"], self.db.getSchema(settings.DATABASE_LAYERS["BEACONS"]["TABLE"], [settings.DATABASE_LAYERS["BEACONS"]["GEOM"], settings.DATABASE_LAYERS["BEACONS"]["PKEY"]]))
self.manageLayers()
#dlg = dlg_FormBearDistLink(["lol","loll","lolly"])
dlg = dlg_FormBearDist(self.db, settings.DATABASE_OTHER_SQL, settings.DATABASE_LAYERS["BEACONS"]["SQL"], self.db.getSchema(settings.DATABASE_LAYERS["BEACONS"]["TABLE"], [settings.DATABASE_LAYERS["BEACONS"]["GEOM"], settings.DATABASE_LAYERS["BEACONS"]["PKEY"]]))
dlg.show()
dlg.exec_()
if bool(dlg.exec_()):
#tmp = ('YE125', 'PBA6015', [[[29.45, 46.29, 'PBA6015', 'PBA6016lol', None, None], 'UPDATE', 0], [[123.0, 123.0, 'PBA6016lol', 'l', None, None], 'INSERT', None], [[123.0, 234.0, 'l', 'lo', None, None], 'INSERT', None], [[123.0, 345.0, 'lo', 'lol', None, None], 'INSERT', None]])
surveyPlan, referenceBeacon, beardistChain = dlg.getReturn()
# check whether survey plan is defined otherwise define it
if not self.db.query(settings.DATABASE_OTHER_SQL["IS_SURVEYPLAN"], (surveyPlan,))[0][0]:
QMessageBox.information(None, "", "need to make a plan about this survey")
self.db.query(settings.DATABASE_OTHER_SQL["INSERT_SURVEYPLAN"], (surveyPlan, referenceBeacon))
# get list of existing links
beardistChainExisting = []
for index, link in enumerate(self.db.query(settings.DATABASE_OTHER_SQL["EXIST_BEARDISTCHAINS"],(surveyPlan,))):
beardistChainExisting.append([list(link), "NULL", index] )
# perform appropriate action for each link in the beardist chain
new = []
old = []
for link in beardistChain:
if link[2] is None: new.append(link)
else: old.append(link)
#QMessageBox.information(None, "", str(beardistChainExisting))
#QMessageBox.information(None, "", str(new))
#QMessageBox.information(None, "", str(old))
# sort out old links
tmp = list(beardistChainExisting)
for elink in beardistChainExisting:
for olink in old:
if elink[2] == olink[2]:
if olink[1] == "NULL":
tmp.remove(elink)
break;
self.db.query(settings.DATABASE_OTHER_SQL["UPDATE_LINK"], [surveyPlan] + olink[0] + [olink[2]])
tmp.remove(elink)
break;
beardistChainExisting = tmp
for elink in beardistChainExisting:
self.db.query(settings.DATABASE_OTHER_SQL["DELETE_LINK"], (elink[0][3],))
# sort out new links
for nlink in new:
self.db.query(settings.DATABASE_OTHER_SQL["INSERT_LINK"], [surveyPlan] + nlink[0])
self.iface.mapCanvas().refresh()

def manageLayers(self):
""" Load layers if not yet loaded
Expand Down Expand Up @@ -296,6 +334,10 @@ def run(self):
slc_ret = slc.exec_()
self.iface.mapCanvas().setMapTool(slc.tool)
if bool(slc_ret):
if self.db.query(self.layersDict["BEACONS"]["SQL"]["BEARDIST"], (slc.getReturn(),))[0][0]:
QMessageBox.warning(None, "Bearing and Distance Definition", "Cannot edit beacon defined by distance and bearing via this tool")
for l in self.layers.values(): l.removeSelection()
return
data = self.db.getSchema(self.layersDict["BEACONS"]["TABLE"], [self.layersDict["BEACONS"]["GEOM"], self.layersDict["BEACONS"]["PKEY"]])
fields = ",".join([f["NAME"] for f in data])
values = [v for v in self.db.query(self.layersDict["BEACONS"]["SQL"]["EDIT"].format(fields = fields), (slc.getReturn(),))[0]]
Expand Down Expand Up @@ -325,6 +367,10 @@ def run(self):
slc_ret = slc.exec_()
self.iface.mapCanvas().setMapTool(slc.tool)
if bool(slc_ret):
if self.db.query(self.layersDict["BEACONS"]["SQL"]["BEARDIST"], (slc.getReturn(),))[0][0]:
QMessageBox.warning(None, "Bearing and Distance Definition", "Cannot delete beacon defined by distance and bearing via this tool")
for l in self.layers.values(): l.removeSelection()
return
self.db.query(self.layersDict["BEACONS"]["SQL"]["DELETE"], (slc.getReturn(),))
for l in self.layers.values(): l.removeSelection()

4 changes: 2 additions & 2 deletions styles/survey.qml
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
<!DOCTYPE qgis PUBLIC 'http://mrcc.com/qgis.dtd' 'SYSTEM'>
<qgis version="1.9.0-Master" minimumScale="0" maximumScale="1e+08" hasScaleBasedVisibilityFlag="0">
<qgis version="1.9.0-Master" minimumScale="-4.65661e-10" maximumScale="1e+08" hasScaleBasedVisibilityFlag="0">
<transparencyLevelInt>255</transparencyLevelInt>
<edittypes>
<edittype type="0" name="id"/>
<edittype type="0" name="plan_no"/>
<edittype allowNull="false" orderByValue="false" key="beacon" layer="beacons20130221110745981" allowMulti="false" filterExpression="" type="15" value="beacon" name="ref_beacon"/>
<edittype allowNull="false" orderByValue="true" key="beacon" layer="beacons20130221110745981" allowMulti="false" filterExpression="" type="15" value="beacon" name="ref_beacon"/>
<edittype allowNull="false" orderByValue="false" key="id" layer="schemes20130211140747478" allowMulti="false" filterExpression="" type="15" value="scheme_name" name="scheme"/>
</edittypes>
<editform>.</editform>
Expand Down

0 comments on commit e8b2722

Please sign in to comment.