import axipy
from rosreestrXml.ui.tools.OutDrv.DbDocuments import DocumentsDb
from rosreestrXml.ui.tools.OutDrv.ObjectToSave import DbGeoOgr, TypeGeometryProviderOgr
from rosreestrXml.ui.tools.cadastral_plan_territory.KPTObj_11Xml import FactoryKpt
from rosreestrXml.ui.tools.cadastral_plan_territory.kpt_11 import parse
from rosreestrXml.ui.tools.kptTools.DbKptDirectory import KptСatalog

#import rosreestrXml.ui.tools.cadastral_plan_territory.kpt_11
path_source=r"E:\Download\RossRestr\report-2dcb0ac2-6dad-49e7-8d0b-44a12f4c1b41-OfSite-2020-09-02-265959-69-010.xml"

#path_source=r"E:\Download\RossRestr\71_01_010401_2023-03-31_kpt11.xml\71_01_010401_2023-03-31_kpt11.xml"
path_out = "E:\\Support\\AxiomaTesting\\XMLKpt\\test.sqlite"
#path_out = r"E:\Download\RossRestr\report-2dcb0ac2-6dad-49e7-8d0b-44a12f4c1b41-OfSite-2020-09-02-265959-69-010Geo.gpkg"
path_out=r"E:\Download\RossRestr\71_01_010401_2023-03-31_kpt11.xml\71_01_010401_2023-03-31_kpt11Building.gpkg"
# path_out="E:\\Support\\AxiomaTesting\\XMLKpt\\testGpkg.gpkg"
dbCatalog=KptСatalog()
dbDoc = None
dbDoc = DocumentsDb(path_out)
db = DbGeoOgr(dbCatalog)
db.Create(path_out, TypeGeometryProviderOgr.GPKG)
db.setDbDocuments(dbDoc)
cs_proj4 = "+proj=eqc +R=6370997 +units=m +no_defs"
cs_wkt = 'LOCAL_CS["NonEarth_Meter",UNIT["METER",1]]'
mi_style = 'Pen (3, 9, 255) Brush (18, 65280)'
mi_style = 'Pen (3, 9, 255) ,Pen (3, 9, 255) Brush (18, 65280)'
ObjKpt=parse(path_source,True)
properties={}
properties['cs']=cs_proj4
properties['zones']={}
properties['zones']['style']=mi_style
properties['zones']['enable']=False

properties['municipal']={}
properties['municipal']['style']=mi_style
properties['municipal']['enable']=False
properties['spatial']={}
properties['spatial']['style']=mi_style
properties['spatial']['enable']=False

properties['land_building']={}
properties['land_building']['style']=mi_style
properties['land_building']['enable']=True
objKpt11= FactoryKpt(ObjKpt,properties)
objZones=objKpt11[0].getObj('zones')
if objZones is not None:
    layer=db.Save(objZones)
objMunicipal=objKpt11[0].getObj('municipal')
if objMunicipal is not None:
    layer=db.Save(objMunicipal)
objspatial=objKpt11[0].getObj('spatial')
if objspatial is not None:
    layer=db.Save(objspatial)
obj_land_building=objKpt11[0].getObj('land_building')
if obj_land_building is not None:
    layer=db.Save(obj_land_building)

db.Close()
print(" End End")
jkl=0