Comparing version 0.1.0 to 0.1.1
{ | ||
"name": "geojsonjs", | ||
"version": "0.1.0", | ||
"version": "0.1.1", | ||
"description": "Build and validate GeoJSON", | ||
@@ -5,0 +5,0 @@ "main": "./src/index.js", |
@@ -76,4 +76,6 @@ # Build and validate GeoJSON with Node.js | ||
Accepts array or object of `type`, `coordinates` and `properties` (optional) | ||
Accepts array or object of `type`, `coordinates` and `properties` (optional). | ||
Also you can parse `GeometryCollection` (object or array of objects). In that case instead of `coordinates` and `properties` it uses `geometries`. | ||
Returns [feature collection](#feature-collection) | ||
@@ -86,17 +88,23 @@ | ||
const featureCollection = parse({ type: 'Point', coordinates: [11, 22] }); | ||
const featureCollection2 = parse([ | ||
{ type: 'Point', coordinates: [11, 22], properties: { prop1: 'prop1' } }, | ||
]); | ||
const point1 = { type: 'Point', coordinates: [11, 22] }; | ||
const point2 = { | ||
type: 'Point', | ||
coordinates: [11, 22], | ||
properties: { prop1: 'prop1' }, | ||
}; | ||
const geometryCollection = { | ||
type: 'GeometryCollection', | ||
geometries: [{ type: 'Point', coordinates: [11, 22] }], | ||
}; | ||
const featureCollection = parse(point1); | ||
const featureCollection2 = parse([point1, point2]); | ||
const featureCollection3 = parse(geometryCollection); | ||
// TypeScript | ||
import { parse, FeatureCollection } from 'geojsonjs'; | ||
const featureCollection: FeatureCollection = parse({ | ||
type: 'Point', | ||
coordinates: [11, 22], | ||
}); | ||
const featureCollection2: FeatureCollection = parse([ | ||
{ type: 'Point', coordinates: [11, 22], properties: { prop1: 'prop1' } }, | ||
]); | ||
const featureCollection: FeatureCollection = parse(point1); | ||
const featureCollection2: FeatureCollection = parse([point1, point2]); | ||
const featureCollection3: FeatureCollection = parse(geometryCollection); | ||
``` | ||
@@ -341,2 +349,4 @@ | ||
- [Geometries (array)](#geometries-array) | ||
- [Geometry collection](#geometry-collection) | ||
- [Geometry collections (array)](#geometry-collections-array) | ||
- [Geometry item types](#geometry-types) | ||
@@ -457,2 +467,43 @@ - Point | ||
### Geometry Collection | ||
```json | ||
{ | ||
"type": "GeometryCollection", | ||
"geometries": [ | ||
{ "type": "Point", "coordinates": [11, 22] }, | ||
{ | ||
"type": "LineString", | ||
"coordinates": [ | ||
[11, 22], | ||
[22, 33] | ||
] | ||
} | ||
] | ||
} | ||
``` | ||
### Geometry Collections (array) | ||
```json | ||
[ | ||
{ | ||
"type": "GeometryCollection", | ||
"geometries": [{ "type": "Point", "coordinates": [11, 22] }] | ||
}, | ||
{ | ||
"type": "GeometryCollection", | ||
"geometries": [ | ||
{ | ||
"type": "LineString", | ||
"coordinates": [ | ||
[11, 22], | ||
[22, 33] | ||
] | ||
} | ||
] | ||
} | ||
] | ||
``` | ||
### Geometry types | ||
@@ -459,0 +510,0 @@ |
import { AllTypes, CoordinatesTypes, Feature, FeatureCollection, GenericObject, Geometry } from './types'; | ||
type ParseData = { | ||
type: string; | ||
coordinates: CoordinatesTypes; | ||
coordinates?: CoordinatesTypes; | ||
geometries?: Geometry[]; | ||
properties?: GenericObject; | ||
@@ -6,0 +7,0 @@ }; |
@@ -33,2 +33,5 @@ "use strict"; | ||
} | ||
if (data.type === types_1.GEOMETRY_COLLECTION) { | ||
return parse(data.geometries); | ||
} | ||
const feature = utils.toFeature(utils.toGeometry(data.type, data.coordinates), data.properties); | ||
@@ -48,2 +51,5 @@ return getFeatureCollection(feature); | ||
} | ||
else if (geom.type === types_1.GEOMETRY_COLLECTION) { | ||
return getFeatures(geom.geometries); | ||
} | ||
else if (geom.type === types_1.FEATURE_COLLECTION_TYPE) { | ||
@@ -50,0 +56,0 @@ return geom.features; |
@@ -10,2 +10,5 @@ export type GenericObject = { | ||
export type CoordinatesMultiPolygon = CoordinatesPolygon[]; | ||
export declare const FEATURE_COLLECTION_TYPE = "FeatureCollection"; | ||
export declare const FEATURE_TYPE = "Feature"; | ||
export declare const GEOMETRY_COLLECTION = "GeometryCollection"; | ||
export type CoordinatesTypes = CoordinatesPoint | CoordinatesLineString | CoordinatesPolygon | CoordinatesMultiPoint | CoordinatesMultiLineString | CoordinatesMultiPolygon; | ||
@@ -16,2 +19,6 @@ export type Geometry = { | ||
}; | ||
export type GeometryCollection = { | ||
type: 'GeometryCollection'; | ||
geometries: Geometry[]; | ||
}; | ||
export type FeatureCollection = { | ||
@@ -26,4 +33,2 @@ type: 'FeatureCollection'; | ||
}; | ||
export declare const FEATURE_COLLECTION_TYPE = "FeatureCollection"; | ||
export declare const FEATURE_TYPE = "Feature"; | ||
export declare const ValidationError: { | ||
@@ -47,3 +52,3 @@ EMTPY: string; | ||
}; | ||
export type AllTypes = Geometry | Geometry[] | Feature | Feature[] | FeatureCollection | FeatureCollection[]; | ||
export type AllTypes = Geometry | Geometry[] | Feature | Feature[] | FeatureCollection | FeatureCollection[] | GeometryCollection | GeometryCollection[]; | ||
export type ValidationResult = { | ||
@@ -50,0 +55,0 @@ valid: boolean; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.GeometryType = exports.ValidationError = exports.FEATURE_TYPE = exports.FEATURE_COLLECTION_TYPE = void 0; | ||
exports.GeometryType = exports.ValidationError = exports.GEOMETRY_COLLECTION = exports.FEATURE_TYPE = exports.FEATURE_COLLECTION_TYPE = void 0; | ||
exports.FEATURE_COLLECTION_TYPE = 'FeatureCollection'; | ||
exports.FEATURE_TYPE = 'Feature'; | ||
exports.GEOMETRY_COLLECTION = 'GeometryCollection'; | ||
exports.ValidationError = { | ||
@@ -7,0 +8,0 @@ EMTPY: 'EMTPY', |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
48776
398
563