ngageoint / geopackage-js

GeoPackage JavaScript Library
http://ngageoint.github.io/geopackage-js/
MIT License
304 stars 78 forks source link

Unable to detect CRS, GeoJSON has no "crs" property #186

Open jfoclpf opened 1 year ago

jfoclpf commented 1 year ago

I am getting this error

Error parsing Geometry Error: Unable to detect CRS, GeoJSON has no "crs" property.
    at detectCrs (/home/joao/dev/geoapi.pt/node_modules/@ngageoint/geopackage/node_modules/reproject/index.js:57:11)
    at Object.reproject (/home/joao/dev/geoapi.pt/node_modules/@ngageoint/geopackage/node_modules/reproject/index.js:98:12)
    at Function.FeatureDao.reprojectFeature (/home/joao/dev/geoapi.pt/node_modules/@ngageoint/geopackage/dist/lib/features/user/featureDao.js:446:44)
    at Object._a.next (/home/joao/dev/geoapi.pt/node_modules/@ngageoint/geopackage/dist/lib/features/user/featureDao.js:389:51)
    at generateMunicipalityCensosJsonFIle (/home/joao/dev/geoapi.pt/routines/censos/generateCensosData.js:260:14)
    at generateJsonData (/home/joao/dev/geoapi.pt/routines/censos/generateCensosData.js:236:5)

with

GeoPackageAPI.open(file).then(geoPackage => {
  const table = geoPackage.getFeatureTables()[0]
  const featureDao = geoPackage.getFeatureDao(table)

  // colums which have statistical numbers to aggregate on the municipality
  const countableColumns = featureDao.columns.filter(c => c.startsWith('N_'))

  // statistical sum for all municipalities
  const sum = {}
  countableColumns.forEach(el => {
    sum[el] = 0
  })

  const geoPackageIterator = geoPackage.iterateGeoJSONFeatures(table)
  for (const feature of geoPackageIterator) { // <= ****** HERE *************
    for (const el in sum) {
      sum[el] += feature.properties[el]
    }
  }
})

I'm using the latest NPM version 4.2.3, and node v16.19.0

Any idea what the problem is?

vgeorge commented 2 months ago

@jfoclpf your file probably doesn't have a CRS set for the table you are querying. I recommend opening it in QGIS to confirm if it is not set and then set it.