ratiopath.parsers.Darwin7JSONParser
Parser for Darwin7 JSON format annotation files.
Extracts geometries and metadata from Darwin JSON structures into a GeoDataFrame. Supports Polygon, Point, and bounding box geometries. Expected JSON schema:
Root
└── annotations (list)
├── Feature (Polygon)
│ ├── id: "uuid"
│ ├── name: "class_name"
│ ├── properties: [...] or {...}
│ ├── slot_names: [...]
│ └── polygon
│ └── paths: [ [ {x, y}, ... ], [holes...] ]
├── Feature (Bounding Box)
│ ├── id: "uuid"
│ └── bounding_box: {x, y, w, h}
└── Feature (Point)
├── id: "uuid"
└── point: {x, y}
Source code in ratiopath/parsers/darwin7_json_parser.py
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 | |
gdf = GeoDataFrame(pd.DataFrame(records), geometry='geometry')
instance-attribute
__init__(file_path)
Source code in ratiopath/parsers/darwin7_json_parser.py
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 | |
extract_nested(val, path)
staticmethod
Extract a nested value from a JSON-like structure using a list of keys.
Source code in ratiopath/parsers/darwin7_json_parser.py
91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 | |
get_filtered_geodataframe(separator='_', **kwargs)
Filter the GeoDataFrame based on property values.
Supports filtering by top-level columns or nested attributes within JSON-like columns (e.g., 'properties'). Nested keys are accessed by joining column names and keys with the separator.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
separator
|
str
|
String used to separate nested keys in kwargs. |
'_'
|
**kwargs
|
str
|
Keyword arguments where keys represent (possibly nested) columns and values are regex patterns to match. |
{}
|
Returns:
| Type | Description |
|---|---|
GeoDataFrame
|
A GeoDataFrame containing only the rows that match all filter criteria. |
GeoDataFrame
|
If a requested top-level column is missing, an empty GeoDataFrame |
GeoDataFrame
|
with the original schema is returned. |
Source code in ratiopath/parsers/darwin7_json_parser.py
112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 | |
get_points(**kwargs)
Get points from the GeoDataFrame.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
**kwargs
|
str
|
Keyword arguments containing regex patterns for filtering properties. |
{}
|
Yields:
| Type | Description |
|---|---|
Iterable[Point]
|
Shapely Point objects. |
Source code in ratiopath/parsers/darwin7_json_parser.py
169 170 171 172 173 174 175 176 177 178 179 | |
get_polygons(**kwargs)
Get polygons from the GeoDataFrame.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
**kwargs
|
str
|
Keyword arguments containing regex patterns for filtering properties. |
{}
|
Yields:
| Type | Description |
|---|---|
Iterable[Polygon]
|
Shapely Polygon objects. |
Source code in ratiopath/parsers/darwin7_json_parser.py
157 158 159 160 161 162 163 164 165 166 167 | |