3liz / QgisCadastrePlugin

A QGIS plugin which helps users to import the french land registry ('cadastre') data into a database. It is meant to ease the use of the data in QGIS by providing search tools and appropriate layer symbology.
GNU General Public License v2.0
61 stars 41 forks source link

Import - Support du millésime 2018 #148

Closed mdouchin closed 5 years ago

mdouchin commented 6 years ago

@landryb j'ai ajouté le support du millésime 2018 dans la branche master (QGIS3). Si tu as déjà des fichiers, pourrais tu tester stp ?

mdouchin commented 6 years ago

C'est ajouté aussi à la branche master_2

mdouchin commented 6 years ago

commits correspondants : 3ff8080924f1ab27008648d4d258ad5eb0cffaa5 et c8c011a578c24025428b19f0e3350ed726d5bf66

landryb commented 6 years ago

Je t'avoue que dans l'immédiat, vu le peu de différences j'avais pris les scripts 2017 vu qu'a priori les changements n'impactaient pas l'utilisation que l'on fait de la base qadastre dans cadastrapp, mais je vais faire un test d'import sur une commune en local.

Dans un premier temps, j'ai essayé d'installer 1.6.0 dans qgis 3.2.1, et le chargement du code m'a insulté:

ModuleNotFoundError: No module named 'future' 
Traceback (most recent call last):
  File "/usr/local/share/qgis/python/qgis/utils.py", line 337, in startPlugin
    plugins[packageName] = package.classFactory(iface)
  File "/home/landry/.local/share/QGIS/QGIS3/profiles/default/python/plugins/cadastre/__init__.py", line 27, in classFactory
    from .cadastre_menu import cadastre_menu
  File "/usr/local/share/qgis/python/qgis/utils.py", line 674, in _import
    mod = _builtin_import(name, globals, locals, fromlist, level)
  File "/home/landry/.local/share/QGIS/QGIS3/profiles/default/python/plugins/cadastre/cadastre_menu.py", line 26, in 
    from future import standard_library
  File "/usr/local/share/qgis/python/qgis/utils.py", line 674, in _import
    mod = _builtin_import(name, globals, locals, fromlist, level)
ModuleNotFoundError: No module named 'future'

j'ai installé la version python3 du module future pour corriger ce problème, mais pour moi ce module n'avait de sens que pour python2 - certes il existe en python3, mais je pense que le code devrait etre adapté pour utiliser des appels différents si l'on est en python2 ou python3.. enfin, je ne suis pas spécialiste python, et encore moins portage 2 vers 3 :)

J'ai des soucis avec le support sqlite/spatialite dans mon qgis donc je ne peux pas faire un vrai test dans l'immédiat, mais j'essaie de résoudre ca.

mdouchin commented 6 years ago

Oups en effet, j'avais laissé traîner ces imports de module future. Je vais corriger cela !

MaelREBOUX commented 6 years ago

ha ben tu m'as gratté su https://github.com/3liz/QgisCadastrePlugin/commit/c8c011a578c24025428b19f0e3350ed726d5bf66#diff-a6a8b0fbe0845ac6a429200e86e3d133

J'avais commencé à le faire pour prendre ma part ^^

merci

mdouchin commented 6 years ago

Désolé @MaelREBOUX j'étais en mode "robot", à force d'habitude de bosser quasi seul sur ce projet. Faut que je change la gouvernance du plugin pour mieux accueillir les bonnes volontés ici présentes ! Notamment accepter plus vite les PR.

MaelREBOUX commented 6 years ago

Pour ma part j'ai fait un git clone directement dans le répertoire .qgis2\python\plugins\ et switcher sur la branche master_2. QGIS 2.18 semble l'accepter. Enfin je suppose car j'ai pu mettre le millésime 2018.

Import en cours.

Je testerai en QGIS 3 sous Ubuntu ensuite.

MaelREBOUX commented 6 years ago

Oups : erreur

ERREUR:  erreur de syntaxe sur ou près de « AS »
LINE 45: ...,173,10))='' THEN NULL ELSE SUBSTRING(tmp,173,10) AS valplaf...

-- Traitement: pevexoneration
INSERT INTO "qgis2_master_2".pevexoneration
(
 pevexoneration, annee,ccodep, ccodir, ccocom, invar, Janbil, dnupev, dnuexb, ccolloc, pexb, gnextl, jandeb, janimp, vecdif, vecdifa, fcexb, fcexba, rcexba,
 dvldif2, dvldif2a, fcexb2, fcexba2, rcexba2,
 valplaf,
 pev, lot
)
SELECT
  REPLACE('2018'||SUBSTRING(tmp,1,3)||SUBSTRING(tmp,7,10)||SUBSTRING(tmp,28,3)||SUBSTRING(tmp,33,3)||CASE WHEN SUBSTRING(tmp,24,4) IS NOT NULL THEN trim(SUBSTRING(tmp,24,4)) ELSE SUBSTRING(tmp,24,4) END, ' ','0') AS pevexoneration,
  '2018',
  SUBSTRING(tmp,1,2) AS ccodep,
  SUBSTRING(tmp,3,1) AS ccodir,
  SUBSTRING(tmp,4,3) AS ccocom,
  SUBSTRING(tmp,7,10) AS invar,

  CASE WHEN SUBSTRING(tmp,24,4) IS NOT NULL THEN trim(SUBSTRING(tmp,24,4)) ELSE SUBSTRING(tmp,24,4) END AS janbil,
  SUBSTRING(tmp,28,3) AS dnupev,

  SUBSTRING(tmp,33,3) AS dnuexb,
  CASE WHEN trim(SUBSTRING(tmp,36,2))='' THEN NULL ELSE trim(SUBSTRING(tmp,36,2)) END AS ccolloc,
  CASE WHEN trim(SUBSTRING(tmp,38,5))='' THEN NULL ELSE to_number(SUBSTRING(tmp,38,5),'99999')/100 END AS pexb,
  CASE WHEN trim(SUBSTRING(tmp,43,2))='' THEN NULL ELSE trim(SUBSTRING(tmp,43,2)) END AS gnextl,
  SUBSTRING(tmp,45,4) AS jandeb,
  SUBSTRING(tmp,49,4) AS janimp,

  SUBSTRING(tmp,53,9) AS vecdif,
  SUBSTRING(tmp,63,9) AS vecdifa,
  SUBSTRING(tmp,73,9) AS fcexb,
  SUBSTRING(tmp,83,9) AS fcexba,
  SUBSTRING(tmp,93,9) AS rcexba,

  CASE WHEN trim(SUBSTRING(tmp,103,9))='' THEN NULL ELSE to_number(SUBSTRING(tmp,103,9),'999999999') END AS dvldif2,

  CASE WHEN trim(SUBSTRING(tmp,113,9))='' THEN NULL ELSE to_number(SUBSTRING(tmp,113,9),'999999999') END AS dvldif2a,

  CASE WHEN trim(SUBSTRING(tmp,123,9))='' THEN NULL ELSE to_number(SUBSTRING(tmp,123,9),'999999999') END AS fcexb2,

  CASE WHEN trim(SUBSTRING(tmp,133,9))='' THEN NULL ELSE to_number(SUBSTRING(tmp,133,9),'999999999') END AS fcexba2,

  CASE WHEN trim(SUBSTRING(tmp,143,9))='' THEN NULL ELSE to_number(SUBSTRING(tmp,143,9),'999999999') END AS rcexba2,

  CASE WHEN trim(SUBSTRING(tmp,173,10))='' THEN NULL ELSE SUBSTRING(tmp,173,10) AS valplaf,

  REPLACE('2018'||SUBSTRING(tmp,1,3)||SUBSTRING(tmp,7,10)||SUBSTRING(tmp,28,3),' ', '0') AS pev,

  '35047' as lot
FROM "qgis2_master_2".bati WHERE SUBSTRING(tmp,31,2) ='30'
mdouchin commented 6 years ago

J'ai oublié le END ! Remplacer AS valplaf par END As valplaf je corrige et pousse

MaelREBOUX commented 6 years ago

oui : vu sur https://github.com/3liz/QgisCadastrePlugin/blob/master_2/scripts/plugin/2018/majic3_formatage_donnees.sql#L410

MaelREBOUX commented 6 years ago

j'ai corrigé en local et tout est passé. je contrôle les données.

landryb commented 6 years ago

Pareil, import OK et chargement de la db sqlite OK, sur une commune seule (63216)

MaelREBOUX commented 6 years ago

J'ai commencé à regarder les données. je vois qu'il manque des valeurs dans le domaine gnextl. je vais faire une PR.

Erreur sur clic sur parcelle :

2018-08-22T10:28:02 1   Traceback (most recent call last):
              File "C:/Users/m.reboux/.qgis2/python/plugins\cadastre\cadastre_menu.py", line 388, in getParcelleInfo
                self.cadastre_search_dialog
              File "C:/Users/m.reboux/.qgis2/python/plugins\cadastre\cadastre_dialogs.py", line 2626, in __init__
                self.setProprietairesContent()
              File "C:/Users/m.reboux/.qgis2/python/plugins\cadastre\cadastre_dialogs.py", line 2732, in setProprietairesContent
                [header, data, rowCount, ok] = cadastre_common.fetchDataFromSqlQuery(self.connector, sql)
              File "C:/Users/m.reboux/.qgis2/python/plugins\cadastre\cadastre_dialogs.py", line 536, in fetchDataFromSqlQuery
                print error_message
            UnicodeEncodeError: 'ascii' codec can't encode character u'\xe9' in position 85: ordinal not in range(128)
landryb commented 6 years ago

J'ai des erreurs sur le chargement des styles, car la table layer_styles n'existe pas dans la db spatialite, mais a priori ca n'empeche pas l'affichage des couches.

2018-08-22T10:34:04     WARNING    Impossible de charger les styles à partir de /tmp/test (requête: SELECT styleQML FROM layer_styles WHERE f_table_schema=NULL AND f_table_name='geo_label' AND f_geometry_column='geom' ORDER BY CASE WHEN useAsDefault THEN 1 ELSE 2 END,update_time DESC LIMIT 1)

Pas de souci a l'utilisation du clic sur parcelle, mais je suis en qgis3/python3..

Bref, en ce qui concerne la problématique 'majic 2018', a part la coquille trouvée (END manquant) pour moi ca parait bien.

mdouchin commented 6 years ago

Merci pour vos retours.

@MaelREBOUX

mdouchin commented 6 years ago

@landryb J'ai créé une branche https://github.com/3liz/QgisCadastrePlugin/tree/remove_future . Peux tu tester et valider que c'est OK chez toi avec ton QGIS 3?

MaelREBOUX commented 6 years ago

@mdouchin désolé j'avais mal regardé. En l'état de ce que je peux voir des données ça m'a l'air OK. Domaines et valeurs (vides...) bien lues.

Comme je le disais dans https://docs.google.com/document/d/1eQcf-k0MEeeLLJZ09Qse1xnoJkI3xe3JD0uwV36Hp4Q l'article 52 reste pour moi pour l'instant un mystère.

ticket #149 créé

landryb commented 6 years ago

@landryb J'ai créé une branche https://github.com/3liz/QgisCadastrePlugin/tree/remove_future . Peux tu tester et valider que c'est OK chez toi avec ton QGIS 3?

Le plugin se charge bien ici avec py3-future désinstallé.

mdouchin commented 6 years ago

merci @landryb je pousse sur master

MaelREBOUX commented 6 years ago

@landryb j'ai enfin un QGIS 3 sous Ubuntu mais il est où le dossier utilisateur de QGIS maintenant ? j'ai pas de .qgis3 dans mon home.

landryb commented 6 years ago

.local/share/QGIS/QGIS3/profiles/default

MaelREBOUX commented 6 years ago

@landryb vu merci.

@mdouchin Je viens de tester sous QGIS 3 branche master et tout est passé. je retrouve les mêmes valeurs que sous QGIS2 branche master_2.

MaelREBOUX commented 6 years ago

@mdouchin on vient de trouver un problème dans la lecture des fichiers Majic III. Il y a une modification de structure dans l'article 50 des propriétés bâties.

Un FILLER a sauté et les valeurs dsupk1 commencent à 72 au lieu de 100 en 2017. Cette modification de structure est non signalée dans la note de version !

L'impact est que tout est à vide ou null ou 0 pour cs 2 attributs.

cf pour le détail https://docs.google.com/document/d/1eQcf-k0MEeeLLJZ09Qse1xnoJkI3xe3JD0uwV36Hp4Q/edit#heading=h.kkh970bwmdn4

MaelREBOUX commented 6 years ago

Je crois que je commence à comprendre comment fonctionne l'import. Chaque ligne est chargée dans une table temporaire d'où on extrait les infos.

Du coup : je me permet 2 PR : 1 pour chaque branche.

mdouchin commented 6 years ago

Merci Maël pour cela. Je regarde. Au sujet des PR, pas besoin de faire sur la branche master_2, je ferai le cherry pick du commit de la master.

mdouchin commented 6 years ago

J'ai fusionné le PR sur master, et fait le cherry-pick sur master_2 @MaelREBOUX merci !

MaelREBOUX commented 6 years ago

@mdouchin @landryb : il reste à traiter le nouvel article 52. Je viens de faire une nouvelle issue #152 à part parce que c'est plus conséquent que les petits ajustements faits jusqu'à présent.

@mdouchin : je veux bien d'un échange tel pour que tu m'expliques dans le détail le mécanisme de chargement. Je pense que je suis pas loin d'avoir compris mais je veux bien être aiguillé STP.

boillodmanuel commented 3 years ago

Bonjour, J'ai rencontré un problème similaire : UnicodeDecodeError: 'ascii' codec can't decode Mon env :

J'ai fini par trouver comment corriger mon problème (la résolution de celui-ci est peut-être similaire)

Dans le fichier cadastre_import.py, fonction replaceParametersInScript, il manque l'encoding sur cette ligne : https://github.com/3liz/QgisCadastrePlugin/blob/2b2c0e3affcf67b49c88bda31f54cdb3b904a617/cadastre/cadastre_import.py#L1015-L1016

Voici le fix:

with open(scriptPath, 'w', encoding='utf-8') as fout:
    fout.write(data)

La locale système ne doit pas être configuré comme il faut dans QGIS. Pour le vérifier, j'ai ouvert la console python (Plugins > Console Python) et exécuté le code suivant :

# Explicitly open with ascii encoding:
# ❌ Error:
#   UnicodeEncodeError: 'ascii' codec can't encode character '\u2122' in position 0: ordinal not in range(128)
with open('/tmp/test', 'w', encoding='ascii') as fout:
    fout.write(u"\u2122")

# Open without encoding specified:
# ❌ Error or ✅ Works depending of system locale :
#   UnicodeEncodeError: 'ascii' codec can't encode character '\u2122' in position 0: ordinal not in range(128)
with open('/tmp/test', 'w') as fout:
    fout.write(u"\u2122")

# Explicitly open with utf-8 encoding:
# ✅ Works
with open('/tmp/test', 'w', encoding='utf-8') as fout:
    fout.write(u"\u2122")

Pour forcer la locale dans QGIS, j'ai ajouté la variable d'environnement LC_ALL dans les préférences (interface en anglais) :.

Je ne suis pas sûr qu'il faille garder ce paramétrage mais ca aide pour débugger.