Esempio n. 1
0
 def installLayer( self, id, schema, table, key, estimated, where, displayname ):
     layer = self.findLayer(id)
     if layer:
         legend = self._iface.legendInterface()
         if not legend.isLayerVisible(layer):
             legend.setLayerVisible(layer, True)
         return layer
     self._statusBar.showMessage("Loading layer " + displayname )
     layer = None
     try:
         uri = QgsDataSourceURI()
         uri.setConnection(Database.host(),Database.port(),Database.database(),Database.user(),Database.password())
         uri.setDataSource(schema,table,'shape',where)
         uri.setKeyColumn( key )
         uri.setUseEstimatedMetadata( estimated )
         layer = QgsVectorLayer(uri.uri(),displayname,"postgres")
         self.setLayerId( layer, id )
         try:
             layer.loadNamedStyle(join(self._styledir,id+'_style.qml'))
         except:
             pass
         QgsMapLayerRegistry.instance().addMapLayer(layer)
     finally:
         self._statusBar.showMessage("")
     return layer
Esempio n. 2
0
    def displayMarkers( self ):
        address = self._address
        enabled = self._enabled
        visible = self._layers.isVisible( self._layers.addressLayer())
        if not enabled or not address or not visible or not address.location():
            self._adrMarker.hide()
            self._sadMarker.hide()
            self._rclMarker.hide()
            return

        transform = QgsCoordinateTransform(self._crs,self._canvas.mapRenderer().destinationCrs())
        point = transform.transform( address.location()[0], address.location()[1])
        self._adrMarker.setCenter( point )
        self._adrMarker.show()

        sadLayer = self._layers.landonlineAddressLayer()
        id = address.sad_id()
        if id and self._layers.isVisible( sadLayer ):
            wkt = Database.executeScalar('elc_GetLandonlineAddressGeometry',id)
            centre = QgsGeometry.fromWkt(wkt)
            centre.transform(transform)
            self._sadMarker.setCenter(centre.asPoint())
            self._sadMarker.show()

        rclLayer = self._layers.landonlineRoadLayer()
        id = address.rcl_id()
        if id and self._layers.isVisible( rclLayer ):
            wkt = Database.executeScalar('elc_GetLandonlineRoadGeometry',id)
            geom = QgsGeometry.fromWkt(wkt)
            self._rclMarker.setToGeometry(geom,rclLayer)
            self._rclMarker.show()
Esempio n. 3
0
 def deleteItem( self, item ):
     if not self._editItem:
         return
     if QMessageBox.question(
         self,
         "Delete supplier",
         "Are you sure you want to remove the supplier " + self._editItem['name'] + '?', 
         QMessageBox.Yes | QMessageBox.No) != QMessageBox.Yes:
         return
     Database.execute('elc_DeleteSupplier',self._editItem['id'])
     self._controller.updateSuppliers()
Esempio n. 4
0
 def deleteItem( self, item ):
     if not self._editItem:
         return
     if QMessageBox.question(
         self,
         "Delete source type",
         "Are you sure you want to remove the source type " + self._editItem['name'] + '?', 
         QMessageBox.Yes | QMessageBox.No) != QMessageBox.Yes:
         return
     Database.execute('elc_DeleteSourceType',self._editItem['id'])
     ReaderType.reload()
     self._controller.updateSourceTypes()
Esempio n. 5
0
 def saveItem( self ):
     if not self.checkIsValid():
         return False
     if self._editItem: 
         id = Database.executeScalar('elc_UpdateSupplier',
                          self._editItem['id'],
                          str(self.uName.text()),
                          self.uSourceType.selectedValue(),
                          self.uTA.selectedValue())
     else:
         id = Database.executeScalar('elc_CreateSupplier',
                          str(self.uName.text()),
                          self.uSourceType.selectedValue(),
                          self.uTA.selectedValue())
     self.clearItem()
     self._controller.updateSuppliers()
     self.uListView.selectId( id )
     return True
Esempio n. 6
0
 def __init__( self, parent=None ):
     QDialog.__init__( self, parent )
     self.setupUi( self )
     self.uHost.setText( Database.host() )
     self.uPort.setText( Database.port() )
     self.uDatabase.setText( Database.database() )
     self.uUser.setText( Database.user() )
     self.uPassword.setText( Database.password() )
     self.uBdeSchema.setText( Database.bdeSchema() )
     self.uAddressSchema.setText( Database.addressSchema() )
     self.uDialogButtons.clicked.connect( self.buttonClicked )
Esempio n. 7
0
    def setPoint( self, coords ):
        src_crs = self._iface.mapCanvas().mapRenderer().destinationCrs()
        tgt_crs = QgsCoordinateReferenceSystem()
        tgt_crs.createFromOgcWmsCrs('EPSG:4167')
        transform = QgsCoordinateTransform( src_crs, tgt_crs )
        wkt = transform.transform( coords.x(), coords.y() ).wellKnownText()

        # Add the point to the database
        success = Database.execute('elc_CreateAddressPoint', self._address.id(), str(wkt))

        if success:
        # Refresh GUI
            self._iface.mapCanvas().refresh()
            self._controller.updateAddress( self._address.id() )
Esempio n. 8
0
    def load( self ):
        self._readerClasses[:] = []
        for sc in Reader.__subclasses__():
            self._readerClasses.append(
                dict(name=sc.__name__,params=sc.params())
                )
        self._readerClasses.sort( key=lambda x: x['name'] )
        for i, c in enumerate( self._readerClasses ):
            self.uReaderClass.addNameValue( c['name'], i )

        for r in Database.execute('select srid, name from elc_getSpatialReferenceSystems() order by name'):
            self.uCoordSys.addNameValue(r[1],r[0])

        self.loadList()
Esempio n. 9
0
    def setSelectRectangle( self, rectangle ):
        src_crs = self._iface.mapCanvas().mapRenderer().destinationCrs()
        tgt_crs = QgsCoordinateReferenceSystem()
        tgt_crs.createFromOgcWmsCrs('EPSG:4167')
        transform = QgsCoordinateTransform( src_crs, tgt_crs )
        searchrect = transform.transformBoundingBox( rectangle )
        wkt = str(QgsGeometry.fromRect(searchrect).exportToWkt())
        jobid = self._controller.job().id()

        self._foundIds[:] = []
        if self._layers.isVisible( self._layers.addressLayer()): 
            for r in Database.execute('select adr_id from elc_findAddressIds(%s,%s) order by poffset',jobid,wkt):
                self._foundIds.append(r[0])
        self._addresses.resetFilter()

        self._foundSad[:] = []
        if self._layers.isVisible( self._layers.landonlineAddressLayer() ):
            for r in Database.execute('select sad_id, rna_id, roadname, housenumber, poffset from elc_findLandonlineAddresses(%s) order by poffset',wkt):
                self._foundSad.append(dict(
                    address=str(r[3])+' '+str(r[2]),
                    sad_id=r[0],
                    rna_id=r[1],
                    offset=round(float(r[4]),1)
                    ))
        self.uSadListView.setList(self._foundSad)

        self._foundRna[:] = []
        if self._layers.isVisible( self._layers.landonlineRoadLayer() ):
            for r in Database.execute('select rna_id, rcl_id, roadname, poffset from elc_findLandonlineRoads(%s) order by poffset',wkt):
                self._foundRna.append(dict(
                    roadname=r[2],
                    rna_id=r[0],
                    rcl_id=r[1],
                    offset=round(float(r[3]),1)
                    ))
        self.uRnaListView.setList(self._foundRna )
Esempio n. 10
0
 def saveItem( self ):
     if not self.checkIsValid():
         return False
     params = ReaderType.encodeParams( self._params.list())
     if self._editItem: 
         id = Database.executeScalar('elc_UpdateSourceType',
                          self._editItem['id'],
                          str(self.uName.text()),
                          str(self.uFileExtension.text()),
                          self.uCoordSys.selectedValue(),
                          str(self.uReaderClass.currentText()),
                          params)
     else:
         id = Database.executeScalar('elc_CreateSourceType',
                          str(self.uName.text()),
                          str(self.uFileExtension.text()),
                          self.uCoordSys.selectedValue(),
                          str(self.uReaderClass.currentText()),
                          params)
     self.clearItem()
     ReaderType.reload()
     self._controller.updateSourceTypes()
     self.uListView.selectId( id )
     return True
Esempio n. 11
0
    def findAddresses( self, rectangle ):
        src_crs = self._iface.mapCanvas().mapRenderer().destinationCrs()
        tgt_crs = QgsCoordinateReferenceSystem()
        tgt_crs.createFromOgcWmsCrs('EPSG:4167')
        transform = QgsCoordinateTransform( src_crs, tgt_crs )
        searchrect = transform.transformBoundingBox( rectangle )
        wkt = str(QgsGeometry.fromRect(searchrect).exportToWkt())

        addresses = []
        for r in Database.execute('select sad_id, rna_id, roadname, housenumber, poffset from elc_findLandonlineAddresses(%s) order by poffset',wkt):
            addresses.append(dict(
                address=str(r[3])+' '+str(r[2]),
                sad_id=r[0],
                rna_id=r[1],
                offset=round(float(r[4]),1)
                ))
        return addresses
Esempio n. 12
0
    def installAddressLayer( self, job, where='' ):
        if not job and not self._adrLayer:
            return

        layerid = self._addressLayerId
        jobwhere = "job_id="+str(self._invalidJobId)
        layername = "Addresses (no job loaded)"
        if( job ):
            jobwhere = "job_id="+str(job.id())+" AND status <> 'MERG'"
            if where:
                jobwhere = jobwhere + ' AND '+where
            layername = 'Addresses (job '+str(job.id())+')'

        layer = self.installLayer( layerid, Database.addressSchema(), 'address', 'adr_id', False, jobwhere, layername )

        if layer.subsetString() != jobwhere:
            layer.setLayerName(layername)
            layer.setSubsetString(jobwhere)
        return layer
Esempio n. 13
0
 def installLandonlineLayers( self ):
     schema = Database.bdeSchema()
     self.installLayer( 'rcl', schema, 'crs_road_ctr_line', 'id', True, "status='CURR'",'Roads' )
     self.installLayer( 'par', schema, 'crs_parcel', 'id', True, 
                                 "status in ('CURR','PEND','APPR') and toc_code='PRIM' and parcel_intent not in ('ROAD','RLWY')",'Parcels' )
     self.installLayer( 'sad', schema, 'crs_street_address', 'id', True, "status='CURR'",'Landonline addresses' )
Esempio n. 14
0
 def load( self ):
     self.loadSourceTypes()
     for r in Database.execute('select stt_id,name from elc_TAList() order by name'):
         self.uTA.addNameValue(r[1],r[0])
     self.loadList()