CataMap

svg_to_mesh module

This modules allows to read an Inkscape SVG file, parse its elements, and convert them to 3D meshes.

svg_to_mesh module API

class catamap.svg_to_mesh.SvgToMesh(concat_mesh='bygroup')[source]

Read SVG, transforms things into meshes

Parameters:

concat_mesh (str) –

concatenation method between multiple paths in SVG file. ‘merge’: merge all paths in a single mesh ‘time’: use mesh timestep to store each path ‘list’: return a list of meshes ‘bygroup’ (default): return a dict of meshes, one for each main

group, paths are concatenated inside each group

document_scale(xml=None, unit='px')[source]

scale from document (px 96 dpi) to target unit

filter_element(style=None)[source]

Assign a processing function / method to the given element, a cleaning function to be called after the associated sub-tree is processed, and a bool to tell if children should be skipped. This method can be overloaded and is called for each XML tree element. The default implementation returns None, which means that there is no specific processing and the default behavior should happen.

Returns:

proc – proc_callable and clean_callable may be None, meaning that normal processing should happen. The processing callable will be called with 3 arguments: (xml_element, transform_matrix, style_dict). The cleaning callable will be called without arguments. if skip_children is True, children are skipped.

Return type:

(proc_callable, clean_callable, skip_children) or None

static get_mesh_color(style)[source]

Returns background_color (fill), foreground_color (borders)

get_transform(trans, previous=None, no_3d=False)[source]
Parameters:
  • trans (str or XML element) – if str: transform field in the SVG element. if element: XML element itself

  • previous (np array or None) – parent transform to be composed with

read_circle(xml_path, trans, style=None)[source]

Read a circle element as a mesh

read_path(xml_path, trans, style=None)[source]

Read a path element as mesh, apply coords transformations

read_paths(xml_et)[source]

Parse XML tree and extract meshes, text and other objects

Parameters:

xml_et (XML tree) – obtained using xml.etree.cElementTree.parse(svg_filename)

read_polygon(xml_path, trans, style=None)[source]

Read a polygon element as a mesh

read_rect(xml_path, trans, style=None)[source]

Read a rectangle element as a mesh

replace_filter_element(xml)[source]

Inside replace_elements, this function is called for each xml element, and should return either the element itself (no replacement), or None (element is discarded), or a replaced XML element.

The default method always returns the input element.

save_mesh_dict(meshes, dirname, mesh_format='.obj', mesh_wf_format='.obj', lights=None)[source]

mesh_format may be a valid mesh extension (“.obj”, “.gii”, “.mesh”) or GLTF (“.gltf” or “.glb”), or None (not saved here).

If GLTF is used a scene dict (JSON) is returned in the output summary under the key “gltf_scene”.

transform_path(xml_path, trans)[source]

trans: transform to be applied

transform_style(xml_path, trans)[source]

adapt style in path/rect to scale changes (stroke width etc)

transform_subtree(xml, in_trans, trans, otrans=None)[source]

in_trans: current transform of xml subtree (out of the subtree) trans: transform to be applied otrans: transform in the output subtree. default=in_trans

static unitscale(unit)[source]

convert unit scale to px (used in inkscape)

class catamap.svg_to_mesh.aims[source]

Fake aims-lite module

class AimsTimeSurface_2[source]

Segments mesh (2 points per polygon)

class AimsTimeSurface_3[source]

Triangles mesh (3 points per polygon)

class vector(dtype, shape)[source]

Fixed size vector

diff_svg module

Print differences between two SVG maps.

Uses the yaml module (pip install pyyaml).

The output is a hierarchical dictionary of differences between the two maps. Differences in tags (properties) and children are recorded. Item keys are their “id” property, which should be unique in the files, and are displayed hierarchically.

Used as a program, the output is in YAML format (mostly human readable)

To use it, try:

python -m catamap.diff_svg --h

It will print the command doc and parameters.

diff_svg module API

catamap.diff_svg.diff_element(el1, el2, verbose_depth=0, verbose_depth_max=1)[source]

Compare two SVG XML trees, record differences in both properties and children in a readable dictionary.

BDAlti maps module

Convertion tools for BDAlti maps (https://geoservices.ign.fr/documentation/diffusion/telechargement-donnees-libres.html#bd-alti) and their use in catamap.

API

catamap.altitude.bdalti.build_meta_table(ima_fnames)[source]

build the metadata table from converted .ima files

ima_fnames: pattern with a “%s”, same as out_fnames in convert_raw_maps()

catamap.altitude.bdalti.convert_raw_map(fname, out_fname)[source]

convert one raw map from bdalti (.asc) to .ima format

catamap.altitude.bdalti.convert_raw_maps(fnames, out_fnames)[source]

convert all raw data files from bdalti (.asc) to .ima format

fnames:

input files pattern (used with glob.glob())

out_fnames:

output files pattern, should contain a “%s” pattern

catamap.altitude.bdalti.get_map_image(xi, yi, meta_map, base)[source]

get image at coords xi, yi in the map table. Lazy load and cache it.

catamap.altitude.bdalti.get_z(x, y, meta_map, base, background_z=-99999.0)[source]

get the altitude from (x, y) coords in Lambert93 coords

TO DO

To do in the future