|
1 | 1 | # Metadata
|
| 2 | +## Meta |
| 3 | +The `Meta` method provides metadata handling capabilities in GeometryBasics. Similarly to remove the metadata and keep only the geometry, use `metafree`, and for vice versa i.e., remove the geometry and keep the metadata use `meta`. |
| 4 | + |
| 5 | + |
| 6 | +### Syntax |
| 7 | +``` |
| 8 | +meta(geometry, meta::NamedTuple) |
| 9 | +meta(geometry; meta...) |
| 10 | +
|
| 11 | +metafree(meta-geometry) |
| 12 | +meta(meta-geometry) |
| 13 | +``` |
| 14 | +### Example |
| 15 | +```jldoctest |
| 16 | +using GeometryBasics |
| 17 | +p1 = Point(2.2, 3.6) |
| 18 | +
|
| 19 | +poi = meta(p1, city="Abuja", rainfall=1221.2) |
| 20 | +2-element PointMeta{2,Int64,Point{2,Int64},(:city, :rainfall),Tuple{String,Float64}} with indices SOneTo(2): |
| 21 | + 3 |
| 22 | + 1 |
| 23 | +
|
| 24 | +# metadata is stored in a NamedTuple and can be retrieved as such |
| 25 | +meta(poi) |
| 26 | +(city = "Abuja", rainfall = 1221.2) |
| 27 | +
|
| 28 | +# specific metadata attributes can be directly retrieved |
| 29 | +poi.rainfall |
| 30 | +1221.2 |
| 31 | +
|
| 32 | +metafree(poi) |
| 33 | +2-element Point{2,Int64} with indices SOneTo(2): |
| 34 | + 3 |
| 35 | + 1 |
| 36 | +
|
| 37 | +# for other geometries metatypes are predefined |
| 38 | +multipoi = MultiPointMeta([p1], city="Abuja", rainfall=1221.2) |
| 39 | +1-element MultiPointMeta{Point{2,Int64},MultiPoint{2,Int64,Point{2,Int64},Array{Point{2,Int64},1}},(:city, :rainfall),Tuple{String,Float64}}: |
| 40 | +[3, 1] |
| 41 | +``` |
| 42 | +In the above example we have also used geometry specific meta methods. |
| 43 | + |
| 44 | +### Example |
| 45 | +```@jldoctest |
| 46 | +GeometryBasics.MetaType(Polygon) |
| 47 | +PolygonMeta |
| 48 | +
|
| 49 | +GeometryBasics.MetaType(Mesh) |
| 50 | +MeshMeta |
| 51 | +``` |
| 52 | +The metageometry objects are infact composed of the original geometry types. |
| 53 | +```@jldoctest |
| 54 | +GeometryBasics.MetaFree(PolygonMeta) |
| 55 | +Polygon |
| 56 | +
|
| 57 | +GeometryBasics.MetaFree(MeshMeta) |
| 58 | +Mesh |
| 59 | +``` |
| 60 | +## MetaT |
| 61 | +In GeometryBasics we can a have tabular layout for a collection of meta-geometries by putting them into a StructArray that extends the [Tables.jl](https://github.com/JuliaData/Tables.jl) API. |
| 62 | + |
| 63 | +In practice it's not necessary for the geometry or metadata types to be consistent. Eg: A geojson format can have heterogeneous geometries. |
| 64 | +Hence, such cases require automatic widening of the geometry data types to the most appropriate type. The MetaT method works around the fact that, a collection of geometries and metadata of different types can be represented tabularly whilst widening to the appropriate type. |
| 65 | +### Syntax |
| 66 | +``` |
| 67 | +MetaT(geometry, meta::NamedTuple) |
| 68 | +MetaT(geometry; meta...) |
| 69 | +``` |
| 70 | +Returns a `MetaT` that holds a geometry and its metadata `MetaT` acts the same as `Meta` method. |
| 71 | +The difference lies in the fact that it is designed to handle geometries and metadata of different/heterogeneous types. |
| 72 | + |
| 73 | +eg: While a Point MetaGeometry is a `PointMeta`, the MetaT representation is `MetaT{Point}` |
| 74 | + |
| 75 | +### Example |
| 76 | +```@jldoctest |
| 77 | +MetaT(Point(1, 2), city = "Mumbai") |
| 78 | +MetaT{Point{2,Int64},(:city,),Tuple{String}}([1, 2], (city = "Mumbai",)) |
| 79 | +``` |
| 80 | + |
| 81 | +For a tabular representation, an iterable of `MetaT` types can be passed on to a `metatable` method. |
| 82 | + |
| 83 | +### Syntax |
| 84 | +```@jldoctest |
| 85 | +meta_table(iter) |
| 86 | +``` |
| 87 | +### Example |
| 88 | +```@jldoctest |
| 89 | +using DataFrames |
| 90 | +# Create an array of 2 linestrings |
| 91 | +ls = [LineString([Point(i, i+1), Point(i-1,i+5)]) for i in 1:2] |
| 92 | +
|
| 93 | +# Create a MultiLineString |
| 94 | +mls = MultiLineString(ls) |
| 95 | +
|
| 96 | +# Create a Polygon |
| 97 | +poly = Polygon(Point{2, Int}[(40, 40), (20, 45), (45, 30), (40, 40)]) |
| 98 | +
|
| 99 | +# Put all of it in an Array |
| 100 | +geom = [ls..., mls, poly] |
| 101 | + |
| 102 | +# Generate some random metadata |
| 103 | +prop = [(country_states = "India$(i)", rainfall = (i*9)/2) for i in 1:4] |
| 104 | + |
| 105 | +# Create an Array of MetaT |
| 106 | +feat = [MetaT(i, j) for (i,j) = zip(geom, prop)] |
| 107 | +
|
| 108 | +# Generate a StructArray/Table |
| 109 | +sa = meta_table(feat) |
| 110 | +
|
| 111 | +sa.main |
| 112 | +sa.country_states |
| 113 | +sa.rainfall |
| 114 | +``` |
| 115 | + |
| 116 | +### Disadvantages: |
| 117 | + * The MetaT is pretty generic in terms of geometry types, it's not subtype to geometries. eg : A `MetaT{Point, NamedTuple{Names, Types}}` is not subtyped to `AbstractPoint` like a `PointMeta` is. |
| 118 | + * This might cause problems on using `MetaT` with other constructors/methods inside or even outside GeometryBasics methods designed to work with the main `Meta` types. |
| 119 | + |
0 commit comments