Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
M
metadata-and-data
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
web-et-numerique
web-et-numerique-internet
data.grandlyon.com
web-portal
components
indexers
metadata-and-data
Commits
b4085e08
Commit
b4085e08
authored
6 years ago
by
Alessandro Cerioni
Browse files
Options
Downloads
Patches
Plain Diff
More robust handling of geometry. Handling of boolean and date types.
parent
f6d3819f
No related branches found
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
5-pg-field-type-detector.py
+3
-3
3 additions, 3 deletions
5-pg-field-type-detector.py
6-doc-processor.py
+3
-1
3 additions, 1 deletion
6-doc-processor.py
utils/postgis_helper.py
+16
-8
16 additions, 8 deletions
utils/postgis_helper.py
with
22 additions
and
12 deletions
5-pg-field-type-detector.py
+
3
−
3
View file @
b4085e08
...
@@ -191,8 +191,8 @@ def generate_field_catalog( cfg, pg, catalog=None ):
...
@@ -191,8 +191,8 @@ def generate_field_catalog( cfg, pg, catalog=None ):
else
:
else
:
output
=
catalog
.
copy
()
output
=
catalog
.
copy
()
# selected_schema = "
abr_arbres_alignement
"
# selected_schema = "
rdata
"
# selected_table = selected_schema + ".
abrarbr
e"
# selected_table = selected_schema + ".
sit_sitra.sittourism
e"
# found = False
# found = False
logging
.
info
(
'
Getting schemas...
'
)
logging
.
info
(
'
Getting schemas...
'
)
...
@@ -217,7 +217,7 @@ def generate_field_catalog( cfg, pg, catalog=None ):
...
@@ -217,7 +217,7 @@ def generate_field_catalog( cfg, pg, catalog=None ):
count
=
'
unknown no. of
'
count
=
'
unknown no. of
'
#print(count)
#print(count)
db_schema_table
=
'
%s
.
%s
'
%
(
pg
.
dbname
,
table
)
db_schema_table
=
'
%s
/
%s
'
%
(
pg
.
dbname
,
table
)
t2
=
time
.
time
()
t2
=
time
.
time
()
logging
.
info
(
'
Analyzing table %s (%s records)...
'
%
(
db_schema_table
,
count
))
logging
.
info
(
'
Analyzing table %s (%s records)...
'
%
(
db_schema_table
,
count
))
logging
.
info
(
'
| %i records were analyzed so far (%.2f records/s)
'
%
(
output
[
'
analyzed_docs
'
],
output
[
'
analyzed_docs
'
]
/
(
t2
-
t1
)))
logging
.
info
(
'
| %i records were analyzed so far (%.2f records/s)
'
%
(
output
[
'
analyzed_docs
'
],
output
[
'
analyzed_docs
'
]
/
(
t2
-
t1
)))
...
...
This diff is collapsed.
Click to expand it.
6-doc-processor.py
+
3
−
1
View file @
b4085e08
...
@@ -44,8 +44,10 @@ def fix_field_types( in_docs, out_types ):
...
@@ -44,8 +44,10 @@ def fix_field_types( in_docs, out_types ):
out_flattened_properties
[
prop
]
=
convert_to_int
(
in_flattened_properties
[
prop
])
out_flattened_properties
[
prop
]
=
convert_to_int
(
in_flattened_properties
[
prop
])
elif
out_types
[
lookup_key
]
==
'
float
'
:
elif
out_types
[
lookup_key
]
==
'
float
'
:
out_flattened_properties
[
prop
]
=
convert_to_float
(
in_flattened_properties
[
prop
])
out_flattened_properties
[
prop
]
=
convert_to_float
(
in_flattened_properties
[
prop
])
elif
out_types
[
lookup_key
]
==
'
datetime
'
:
elif
out_types
[
lookup_key
]
in
[
'
date
'
,
'
datetime
'
]
:
out_flattened_properties
[
prop
]
=
convert_to_datetime
(
in_flattened_properties
[
prop
]).
strftime
(
'
%Y-%m-%dT%H:%M:%SZ
'
)
out_flattened_properties
[
prop
]
=
convert_to_datetime
(
in_flattened_properties
[
prop
]).
strftime
(
'
%Y-%m-%dT%H:%M:%SZ
'
)
elif
out_types
[
lookup_key
]
==
'
bool
'
:
out_flattened_properties
[
prop
]
=
convert_to_boolean
(
in_flattened_properties
[
prop
])
else
:
else
:
logging
.
critical
(
'
type %s not supported
'
,
out_types
[
prop
])
logging
.
critical
(
'
type %s not supported
'
,
out_types
[
prop
])
sys
.
exit
(
1
)
sys
.
exit
(
1
)
...
...
This diff is collapsed.
Click to expand it.
utils/postgis_helper.py
+
16
−
8
View file @
b4085e08
...
@@ -88,21 +88,29 @@ class Remote(object):
...
@@ -88,21 +88,29 @@ class Remote(object):
selected
=
select
(
fields
)
selected
=
select
(
fields
)
for
entry
in
self
.
engine
.
execute
(
selected
):
for
entry
in
self
.
engine
.
execute
(
selected
):
items
=
entry
.
items
()
items
=
entry
.
items
()
#print(items)
if
geom
is
not
None
:
try
:
geometry
=
json
.
loads
(
items
.
pop
()[
1
])
except
TypeError
:
geom
=
None
properties
=
dict
(
items
)
properties
=
dict
(
items
)
geometry
=
None
try
:
geometry
=
json
.
loads
(
properties
[
'
ST_AsGeoJSON_1
'
])
del
properties
[
'
ST_AsGeoJSON_1
'
]
except
:
pass
# #print(items)
# if geom is not None:
# try:
# geometry = json.loads(items.pop()[1])
# except TypeError:
# geom = None
#properties = dict(items)
document
=
{
document
=
{
'
type
'
:
'
Feature
'
,
'
type
'
:
'
Feature
'
,
'
properties
'
:
properties
'
properties
'
:
properties
}
}
if
geom
is
not
None
:
if
geom
etry
is
not
None
:
document
[
'
geometry
'
]
=
geometry
document
[
'
geometry
'
]
=
geometry
yield
document
yield
document
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment