|
1 | 1 | # Metadata
|
| 2 | +```julia |
| 3 | +p1 = Point(2.2, 3.6) |
| 4 | + |
| 5 | +# geometries can carry metadata |
| 6 | +poi = meta(p1, city="Abuja", rainfall=1221.2) |
| 7 | +2-element PointMeta{2,Int64,Point{2,Int64},(:city, :rainfall),Tuple{String,Float64}} with indices SOneTo(2): |
| 8 | + 3 |
| 9 | + 1 |
| 10 | + |
| 11 | +# metadata is stored in a NamedTuple and can be retrieved as such |
| 12 | +meta(poi) |
| 13 | +(city = "Abuja", rainfall = 1221.2) |
| 14 | + |
| 15 | +# specific metadata attributes can be directly retrieved |
| 16 | +poi.rainfall |
| 17 | +1221.2 |
| 18 | + |
| 19 | +# to remove the metadata and keep only the geometry, use metafree |
| 20 | +metafree(poi) |
| 21 | +2-element Point{2,Int64} with indices SOneTo(2): |
| 22 | + 3 |
| 23 | + 1 |
| 24 | + |
| 25 | +# for other geometries metatypes are predefined |
| 26 | +multipoi = MultiPointMeta([p1], city="Abuja", rainfall=1221.2) |
| 27 | +1-element MultiPointMeta{Point{2,Int64},MultiPoint{2,Int64,Point{2,Int64},Array{Point{2,Int64},1}},(:city, :rainfall),Tuple{String,Float64}}: |
| 28 | +[3, 1] |
| 29 | +``` |
| 30 | + |
| 31 | +## MetaT |
| 32 | +In GeometryBasics we can a have tabular layout for a collection meta-geometries by putting them into a StructArray that extends the Tables.jl API. |
| 33 | + |
| 34 | +In practice it's not necessary for the geometry or metadata types to be consistent. Eg: A .geojson format can have heterogeneous geometries. |
| 35 | +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. |
| 36 | +### Syntax |
| 37 | +```julia |
| 38 | + MetaT(geometry, meta::NamedTuple) |
| 39 | + MetaT(geometry; meta...) |
| 40 | +``` |
| 41 | +Returns a `MetaT` that holds a geometry and its metadata `MetaT` acts the same as `Meta` method. |
| 42 | +The difference lies in the fact that it is designed to handle geometries and metadata of different/heterogeneous types. |
| 43 | + |
| 44 | +eg: While a Point MetaGeometry is a `PointMeta`, the MetaT representation is `MetaT{Point}` |
| 45 | + |
| 46 | +#### Example: |
| 47 | +```julia |
| 48 | +MetaT(Point(1, 2), city = "Mumbai") |
| 49 | +MetaT{Point{2,Int64},(:city,),Tuple{String}}([1, 2], (city = "Mumbai",)) |
| 50 | +``` |
| 51 | + |
| 52 | +For a tabular representation, an iterable of `MetaT` types can be passed on to a `metatable` method. |
| 53 | + |
| 54 | +### Syntax |
| 55 | +```julia |
| 56 | + meta_table(iter) |
| 57 | +``` |
| 58 | +#### Example: |
| 59 | +```julia |
| 60 | +using DataFrames |
| 61 | +# Create an array of 2 linestrings |
| 62 | +ls = [LineString([Point(i, i+1), Point(i-1,i+5)]) for i in 1:2] |
| 63 | + |
| 64 | +# Create a MultiLineString |
| 65 | +mls = MultiLineString(ls) |
| 66 | + |
| 67 | +# Create a Polygon |
| 68 | +poly = Polygon(Point{2, Int}[(40, 40), (20, 45), (45, 30), (40, 40)]) |
| 69 | + |
| 70 | +# Put all of it in an Array |
| 71 | +geom = [ls..., mls, poly] |
| 72 | + |
| 73 | +# Generate some random metadata |
| 74 | +prop = [(country_states = "India$(i)", rainfall = (i*9)/2) for i in 1:4] |
| 75 | + |
| 76 | +# Create an Array of MetaT |
| 77 | +feat = [MetaT(i, j) for (i,j) = zip(geom, prop)] |
| 78 | + |
| 79 | +# Generate a StructArray/Table |
| 80 | +sa = meta_table(feat) |
| 81 | + |
| 82 | +sa.main |
| 83 | +sa.country_states |
| 84 | +sa.rainfall |
| 85 | +``` |
| 86 | + |
| 87 | +### Disadvantages: |
| 88 | + * The MetaT is pretty generic in terms of geometry types, it's not subtype to geometries. |
| 89 | + eg : A `MetaT{Point, NamedTuple{Names, Types}}` is not subtyped to `AbstractPoint` like a `PointMeta` is. |
| 90 | + * 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. |
| 91 | + |
0 commit comments