Phrogz / svg2geojson

Converts an SVG file with added geo-referencing tags into one or more GeoJSON files.
MIT License
57 stars 30 forks source link

Pass svg attribute data to geojson features. #6

Open wizzfizz94 opened 6 years ago

wizzfizz94 commented 6 years ago

Need a way pass attribute data across. possibly to feature properties.

Phrogz commented 6 years ago

Can you elaborate on this request? What attribute data do you want passed, to where/what function, for what purpose?

Phrogz commented 4 years ago

@wizzfizz94 Ping.

Crisfole commented 4 years ago

I'm not wizzfizz, but we're have something like this:

<g id="WATER">
  <path id="POOL" d="M11333.8,11015C11356.3,11167 11234.8,11334.9 11330.6,11448.9C11426.5,11562.9 11705,11651.8 11801.8,11507C11898.6,11362.2 11974.9,11173.8 11974.9,10979.8C11974.9,10785.8 11940.3,10569.1 11859.3,10440.8C11778.2,10312.6 11603.4,10207.8 11429.7,10302.1C11256,10396.4 11162.1,10541.9 11203.3,10693.8C11244.5,10845.8 11312.1,10868.5 11333.8,11015Z" style="fill:rgb(189,222,229);"/>
</g>

And we'd like the ID passed through to the feature. Not terribly fussy about how its formatted, just so we can find it programatically:

{
  "type": "Feature",
  "properties": {
    "id": "POOL",
    "class": "WATER WATERSPARENT"
  },
  "geometry": {
    "type": "Polygon",
    "coordinates": [
      [
        [
          -122.24306374398041,
          47.922757305314946
        ],
        [
          -122.2430642555439,
          47.922748481530625
        ],
        [
          -122.2430681239193,
          47.92273548453174
        ],
        [
          -122.2430671292968,
          47.922727705575326
        ],
        [
          -122.2430641094084,
          47.922724268647684
        ],
        [
          -122.24305263607624,
          47.922718365265915
        ],
        [
          -122.24302929594788,
          47.92271411109429
        ],
        [
          -122.2430153368401,
          47.92271651369286
        ],
        [
          -122.24301030013899,
          47.922719844977784
        ],
        [
          -122.24300254799846,
          47.922728690889976
        ],
        [
          -122.24299206692459,
          47.92274903234796
        ],
        [
          -122.24299053276944,
          47.92275998540411
        ],
        [
          -122.2429912946725,
          47.92277125550739
        ],
        [
          -122.24299776888572,
          47.922792567974234
        ],
        [
          -122.24300373385506,
          47.92280102426942
        ],
        [
          -122.24301251697355,
          47.922807801939854
        ],
        [
          -122.24303099508538,
          47.922813972268756
        ],
        [
          -122.24304536935894,
          47.9228135927342
        ],
        [
          -122.24305279256077,
          47.92281158473438
        ],
        [
          -122.24306586214229,
          47.922805522174734
        ],
        [
          -122.2430777639557,
          47.9227943868611
        ],
        [
          -122.24307970007268,
          47.922786068686634
        ],
        [
          -122.24307864659005,
          47.922781761128554
        ],
        [
          -122.2430703602252,
          47.92276937618528
        ],
        [
          -122.24306374398041,
          47.922757305314946
        ],
        [
          -122.24306374398041,
          47.922757305314946
        ]
      ]
    ]
  }
}
wizzfizz94 commented 4 years ago

Yes the feature that @Crisfole would like is what i meant. The ability to for all arbitrary svg attributes to be included in the geojosn parse. I think i ended up hacking the module but for a hacky hard coded fix so i wont upload it.

DavidCampbellTech commented 4 years ago

We too have the same need. We'd like to pass id's on svg elements (not just the group) all the way through to the postgis database, svg -> geojson -> shape file - db.

Its quite important in order to make interactive maps.

SimonasPetk commented 2 years ago

I solved this issue by running in debug mode. As debug mode adds svgID into the properties field. (see lib/svg2geojson.js, line 68 for part of code responsible for it.)

svg2geojson ../clean-1-part.svg --debug

returns

{"type":"Feature","properties":{"svgID":"1"},"geometry":{"type":"LineString","coordinates":[...........]}}