Re: [QGIS-it-user] pyQgis: come verificare una gemetria id=X nel corso di un ciclo?

2016-11-06 Thread Luca Mandolesi
Ciao Marco.
per ora devo solo mandare fuori l'id delle 2 geometrie e la verifica della
presenza di intersezione. Dal cookbook si arriva bene qua:

iter = vlayer.getFeatures()

Faccio un loop sulle singole geometrie e se becco il rapporto copre
 ricavare da iter la feature id=x senza fare un loop.

Tipo con una chiamata:
#singFeat = vlayer.featureAtId(1)

Ma mi dice che vlayer non ha featureAtId come metodo
E' possibile?

Grazie
Luca

#
Dilungandosi nei particolari

Il loop è eseguito su un tabella view che fonde la tabella spaziale con la
tabella alfanumerica.

Quindi se nel campo rapporto c'è scritto 1 copre 2, devo chiamare le
geometrie di 1 e 2 e fare un verifica l'intersezione.

Facendo un loop sulla view accedo al campo rapporti, quando si verifica la
condizione "copre" (e fin qui ci sono come script python) allora nel loop
dal provider devo ricavare la geometria ed è qui che non capisco come
accedere dal provider al dato geometry.

uri = QgsDataSourceURI()
uri.setDatabase('C:\\Users\\Luca\\pyarchinit_DB_folder\\pyarchinit_db.sqlite')
uri.setDataSource('','pyarchinit_us_view', 'the_geom')

provider = vlayer.dataProvider()
iter = vlayer.getFeatures()

vlayer = QgsVectorLayer(uri.uri(), 'pyarchinit_us_view', 'spatialite')

for feature in iter:
for sing_us in feature[31]: #il 31 è il campo che contiene il
rapporto in formato lista ['copre', '2']
#a questo punto avrei bisogno di dire
a = feature
b = iter.(cerca la feature id=2).feature() #<- qui c'è il punto
in cui non riesco a recuperare la geometria della feature senza fare un iter
return sing_us, a.geometry().intersects(b.geometry())


Alla fine otterrei un valore di rapporto copre e un false o true per
l'intersezione che andrò a gestire in una tabella esterna dove visualizzo
il rapporto alfanumerico richiesto e farò apparire le 2 geometrie in ballo.
Sarà poi l'utente a decidere se è il disegno sbagliato oppure il dato
alfanumerico inserito ad essere errato.





Il giorno 5 novembre 2016 17:11, Marco Grisolia 
ha scritto:

> Ciao,
> non ho capito se vuoi sapere soltanto quali siano le features che si
> intersecano tra loro (ad es. una lista) oppure se devi fare un ulteriore
> controllo su di esse una volta verificata l'intersezione (ad esempio: se la
> feature "a" interseca altre 3 features all'interno del layer, verificare
> che a["id_us"] sia pari a 3).
> A prescindere dall'obiettivo, vuoi solo stampare qualcosa o modificare gli
> attributi?
> Marco
>
> Il giorno 5 novembre 2016 09:53, Luca Mandolesi  ha
> scritto:
>
>> Scusate, partito l'invio, il print di prima era un errore.
>>
>> Io pensavo ad una cosa tipo [0], ma ricevo poi errore perchè a e b non
>> accedono a geometry:
>>
>> [0]
>> request = QgsFeatureRequest().setFilterExpression( '"id_us" = 2' )
>> a = vlayer.getFeatures( request )
>> request = QgsFeatureRequest().setFilterExpression( '"id_us" = 3' )
>> b = vlayer.getFeatures( request )
>>
>> a.geometry().intersects(b.geometry())
>>
>> Grazie per i suggerimenti.
>> Luca
>>
>> ___
>> QGIS-it-user mailing list
>> QGIS-it-user@lists.osgeo.org
>> http://lists.osgeo.org/mailman/listinfo/qgis-it-user
>>
>>
>
___
QGIS-it-user mailing list
QGIS-it-user@lists.osgeo.org
http://lists.osgeo.org/mailman/listinfo/qgis-it-user


Re: [QGIS-it-user] pyQgis: come verificare una gemetria id=X nel corso di un ciclo?

2016-11-06 Thread Giuliano Curti
On 11/6/16, Luca Mandolesi  wrote:
> Il giorno 6 novembre 2016 13:33, Giuliano Curti  ha
> scritto:
>
>> On 11/6/16, Luca Mandolesi  wrote:
>
> mentre sono in un ciclo for e analizzo il campo di un record, come faccio a
> chiamare un altro record e caricarne la geometria.

rimango sempre nel dubbio di aver capito bene :-) questo spezzone di
codice cmq ti dà le due feature f1 e f2, le rispettive geometrie, le
confronta (scartando ovviamente il controllo
con sè stessa) e puoi accedere ad ogni altro loro attributo;

for f1 in layer.getFeatures():
..
for f2 in layer.getFeatures():

if f2.id() <> f1.id():
.
if f1.geometry().intersects(f2.geometry()):
(controllo se l'attributo delle due 
feature è corretto)
...

NB: per il tuo caso forse è ridondante perchè confronta A con B e B
con A, mentre a te potrebbe bastare confrontare A con B, ad es.
modificando il test in
if f2.id() > f1.id():
o qualche modo migliore che sapranno indicarti altri;

> Ciao
> Luca

ciao,
giuliano
___
QGIS-it-user mailing list
QGIS-it-user@lists.osgeo.org
http://lists.osgeo.org/mailman/listinfo/qgis-it-user


Re: [Qgis-user] Joining data to a shape file by country name when the names don't match exactly

2016-11-06 Thread Nicolas Cadieux
Hi,
Stick to Excel for now.  Keep in mind that Python can be used in the Python 
console.  Building a for al plugin may not be necessary.  Have you tried the 
vlookup function?  It has a "close match algorithm " by default.  That may help.
Nicolas

> Le 5 nov. 2016 à 22:30, Joe Lertola [via OSGeo.org] 
>  a écrit :
> 
> I used to program in my youth so I am familiar with programming concepts. But 
> I would have to learn python and how to create plugins for Qgis from scratch. 
> So that is not a project that will happen very fast if I do it. If it turns 
> out that I have to create a lot of maps like this I might start looking into 
> it. For now I will stick to Excel.
> -Joe
> 
> 
> 
> Thanks,
> -Joe
> 
> 
>> On Nov 5, 2016, at 9:57 AM, Nicolas Cadieux <[hidden email]> wrote:
>> 
>> Very interesting Nyall 
>> 
>> That makes me remember that the vlookup in excel also has a "bests match" by 
>> default.  I always turn it off because it uses the first found possible 
>> match.  I wonder if it uses the same type of "Fuzzy" logic...?  
>> 
>> Nicolas
>> 
>>> Le 4 nov. 2016 à 23:22, Nyall Dawson [via OSGeo.org] <>> href="x-msg://34/user/SendEmail.jtp?type=nodenode=5294431i=0" 
>>> target="_top" rel="nofollow" link="external" class="">[hidden email]> a 
>>> écrit :
>>> 
>>> 
>>> On 5 Nov 2016 12:13 PM, "Joe Lertola" <>> href="x-msg://34/user/SendEmail.jtp?type=nodenode=5294406i=0" 
>>> target="_top" rel="nofollow" link="external" class="">[hidden email]> wrote:
>>> >
>>> > Hello.
>>> >
>>> > Today I made a thematic map by joining a list of data that had country 
>>> > names to a shape file of world countries. I had to spend a lot of time 
>>> > working in Excel to make my data names match the names in the shape file. 
>>> > A lot of them already matched but there were many that didn’t. For 
>>> > example the the shape file had Ivory Coast and the data had Cte d’Ivoire 
>>> > as the name. Is there any way to do this in Qgis instead of Excel? Years 
>>> > ago I recall doing this in ArcMap. There was a tool that matched up the 
>>> > data where it could and then for each record that wasn’t matched you 
>>> > could choose the matching record manually. Any help would be greatly 
>>> > appreciated.
>>> 
>>> How good are your python skills? Sounds like a perfect candidate for a new 
>>> processing algorithm. QgsStringUtils has methods for performing "fuzzy" 
>>> matching of strings, so a lot of the hard work is already done.
>>> 
>>> Nyall
>>> 
>>> >
>>> > Thanks,
>>> > -Joe
>>> >
>>> >
>>> > ___
>>> > Qgis-user mailing list
>>> > >> > href="x-msg://34/user/SendEmail.jtp?type=nodenode=5294406i=1" 
>>> > target="_top" rel="nofollow" link="external" class="">[hidden email]
>>> > List info: http://lists.osgeo.org/mailman/listinfo/qgis-user
>>> > Unsubscribe: http://lists.osgeo.org/mailman/listinfo/qgis-user
>>> 
>>> 
>>> ___ 
>>> Qgis-user mailing list 
>>> >> target="_top" rel="nofollow" link="external" class="">[hidden email] 
>>> List info: http://lists.osgeo.org/mailman/listinfo/qgis-user
>>> Unsubscribe: http://lists.osgeo.org/mailman/listinfo/qgis-user 
>>> 
>>> If you reply to this email, your message will be added to the discussion 
>>> below:
>>> http://osgeo-org.1560.x6.nabble.com/Fwd-Joining-data-to-a-shape-file-by-country-name-when-the-names-don-t-match-exactly-tp5294403p5294406.html
>>> To start a new topic under Quantum GIS - User, email >> href="x-msg://34/user/SendEmail.jtp?type=nodenode=5294431i=1" 
>>> target="_top" rel="nofollow" link="external" class="">[hidden email] 
>>> To unsubscribe from Quantum GIS - User, click here.
>>> NAML
>> 
>> View this message in context: Re: Joining data to a shape file by country 
>> name when the names don't match exactly
>> Sent from the Quantum GIS - User mailing list archive at Nabble.com.
>> ___
>> Qgis-user mailing list
>> [hidden email]
>> List info: http://lists.osgeo.org/mailman/listinfo/qgis-user
>> Unsubscribe: http://lists.osgeo.org/mailman/listinfo/qgis-user
> 
> 
> 
> ___ 
> Qgis-user mailing list 
> [hidden email] 
> List info: http://lists.osgeo.org/mailman/listinfo/qgis-user
> Unsubscribe: http://lists.osgeo.org/mailman/listinfo/qgis-user 
> 
> If you reply to this email, your message will be added to the discussion 
> below:
> http://osgeo-org.1560.x6.nabble.com/Fwd-Joining-data-to-a-shape-file-by-country-name-when-the-names-don-t-match-exactly-tp5294403p5294475.html
> To start a new topic under Quantum GIS - User, email 
> ml-node+s1560n4125267...@n6.nabble.com 
> To unsubscribe from Quantum GIS - User, click here.
> NAML




--
View this message in context: 
http://osgeo-org.1560.x6.nabble.com/Fwd-Joining-data-to-a-shape-file-by-country-name-when-the-names-don-t-match-exactly-tp5294403p5294502.html
Sent from the Quantum GIS - User 

Re: [Qgis-user] Joining data to a shape file by country name when the names don't match exactly

2016-11-06 Thread Joe Lertola
Thanks, 

I will keep in mind the idea of making a plugin if I need to accomplish this 
task more often in the future. I don’t know if the Python console would work 
because there would need to be an interface for the user to manually select 
records that can not be matched exactly. Can that be written for code that goes 
into the Python console?

I did use that vlookup function in Excel which is great when the names match 
exactly. But the close match algorithm is not good because it is more likely 
than not to find the wrong country name. What you need to do when a record does 
not match is to manually correct it. This is tedious when there are a lot of 
names that don’t match.

-Joe


> On Nov 6, 2016, at 10:21 AM, Nicolas Cadieux  
> wrote:
> 
> Hi,
> Stick to Excel for now.  Keep in mind that Python can be used in the Python 
> console.  Building a for al plugin may not be necessary.  Have you tried the 
> vlookup function?  It has a "close match algorithm " by default.  That may 
> help.
> Nicolas
> 
> Le 5 nov. 2016 à 22:30, Joe Lertola [via OSGeo.org ] 
> <[hidden email] > a 
> écrit :
> 
>> I used to program in my youth so I am familiar with programming concepts. 
>> But I would have to learn python and how to create plugins for Qgis from 
>> scratch. So that is not a project that will happen very fast if I do it. If 
>> it turns out that I have to create a lot of maps like this I might start 
>> looking into it. For now I will stick to Excel.
>> -Joe
>> 
>> 
>> 
>> Thanks,
>> -Joe
>> 
>> 
>>> On Nov 5, 2016, at 9:57 AM, Nicolas Cadieux <[hidden email] 
>>> > wrote:
>>> 
>>> Very interesting Nyall 
>>> 
>>> That makes me remember that the vlookup in excel also has a "bests match" 
>>> by default.  I always turn it off because it uses the first found possible 
>>> match.  I wonder if it uses the same type of "Fuzzy" logic...?  
>>> 
>>> Nicolas
>>> 
>>> Le 4 nov. 2016 à 23:22, Nyall Dawson [via OSGeo.org ] 
>>> <>> target="_top" rel="nofollow" link="external" class="">[hidden email]> a 
>>> écrit :
>>> 
 
 On 5 Nov 2016 12:13 PM, "Joe Lertola" <>>> href="x-msg://34/user/SendEmail.jtp?type=nodenode=5294406i=0" 
 target="_top" rel="nofollow" link="external" class="">[hidden email]> 
 wrote:
 >
 > Hello.
 >
 > Today I made a thematic map by joining a list of data that had country 
 > names to a shape file of world countries. I had to spend a lot of time 
 > working in Excel to make my data names match the names in the shape 
 > file. A lot of them already matched but there were many that didn’t. For 
 > example the the shape file had Ivory Coast and the data had Cte d’Ivoire 
 > as the name. Is there any way to do this in Qgis instead of Excel? Years 
 > ago I recall doing this in ArcMap. There was a tool that matched up the 
 > data where it could and then for each record that wasn’t matched you 
 > could choose the matching record manually. Any help would be greatly 
 > appreciated.
 
 How good are your python skills? Sounds like a perfect candidate for a new 
 processing algorithm. QgsStringUtils has methods for performing "fuzzy" 
 matching of strings, so a lot of the hard work is already done.
 
 Nyall
 
 >
 > Thanks,
 > -Joe
 >
 >
 > ___
 > Qgis-user mailing list
 > >>> > href="x-msg://34/user/SendEmail.jtp?type=nodenode=5294406i=1" 
 > target="_top" rel="nofollow" link="external" class="">[hidden email]
 > List info: http://lists.osgeo.org/mailman/listinfo/qgis-user 
 > 
 > Unsubscribe: http://lists.osgeo.org/mailman/listinfo/qgis-user 
 > 
 
 ___ 
 Qgis-user mailing list 
 >>> target="_top" rel="nofollow" link="external" class="">[hidden email] 
 List info: http://lists.osgeo.org/mailman/listinfo/qgis-user 
 
 Unsubscribe: http://lists.osgeo.org/mailman/listinfo/qgis-user 
  
 
 If you reply to this email, your message will be added to the discussion 
 below:
 http://osgeo-org.1560.x6.nabble.com/Fwd-Joining-data-to-a-shape-file-by-country-name-when-the-names-don-t-match-exactly-tp5294403p5294406.html
  
 
 To start a new topic under Quantum GIS - User, email >>> href="x-msg://34/user/SendEmail.jtp?type=nodenode=5294431i=1" 
 target="_top" rel="nofollow" link="external" class="">[hidden email] 
 To unsubscribe from Quantum GIS - User, click here 
 .
 NAML