Skip to content

Commit

Permalink
Merge branch 'curve-geoms' (yocontra#8)
Browse files Browse the repository at this point in the history
  • Loading branch information
mmomtchev committed May 5, 2021
2 parents 84e9c8b + c7b8ebf commit cbe4566
Show file tree
Hide file tree
Showing 53 changed files with 1,631 additions and 603 deletions.
23 changes: 14 additions & 9 deletions binding.gyp
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,19 @@
"src/gdal_feature.cpp",
"src/gdal_feature_defn.cpp",
"src/gdal_field_defn.cpp",
"src/gdal_geometry.cpp",
"src/gdal_point.cpp",
"src/gdal_linestring.cpp",
"src/gdal_linearring.cpp",
"src/gdal_polygon.cpp",
"src/gdal_geometrycollection.cpp",
"src/gdal_multipoint.cpp",
"src/gdal_multilinestring.cpp",
"src/gdal_multipolygon.cpp",
"src/geometry/gdal_geometry.cpp",
"src/geometry/gdal_point.cpp",
"src/geometry/gdal_simplecurve.cpp",
"src/geometry/gdal_compoundcurve.cpp",
"src/geometry/gdal_linestring.cpp",
"src/geometry/gdal_circularstring.cpp",
"src/geometry/gdal_linearring.cpp",
"src/geometry/gdal_polygon.cpp",
"src/geometry/gdal_geometrycollection.cpp",
"src/geometry/gdal_multipoint.cpp",
"src/geometry/gdal_multilinestring.cpp",
"src/geometry/gdal_multicurve.cpp",
"src/geometry/gdal_multipolygon.cpp",
"src/gdal_layer.cpp",
"src/gdal_coordinate_transformation.cpp",
"src/gdal_spatial_reference.cpp",
Expand All @@ -53,6 +57,7 @@
"src/collections/geometry_collection_children.cpp",
"src/collections/polygon_rings.cpp",
"src/collections/linestring_points.cpp",
"src/collections/compound_curves.cpp",
"src/collections/rasterband_overviews.cpp",
"src/collections/rasterband_pixels.cpp",
"src/collections/gdal_drivers.cpp"
Expand Down
204 changes: 202 additions & 2 deletions lib/gdal.js
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,20 @@ function defaultToArray() {
return array
}

function defaultIterator() {
let i = 0

return {
next: () => {
const done = !(i < this.count())
return {
done,
value: done ? null : this.get(i++)
}
}
}
}

/**
* Iterates through all bands using a callback function.
* Note: GDAL band indexes start at 1, not 0.
Expand Down Expand Up @@ -176,6 +190,31 @@ gdal.DatasetBands.prototype.forEach = function (callback) {
*/
gdal.DatasetBands.prototype.map = defaultMap

/**
* Iterates through all bands using an iterator
*
* @example
* ```
* for (const band of dataset.bands) {
* }```
*
* @for gdal.DatasetBands
* @method Symbol.iterator
*/
gdal.DatasetBands.prototype[Symbol.iterator] = function defaultIterator() {
let i = 1

return {
next: () => {
const done = !(i <= this.count())
return {
done,
value: done ? null : this.get(i++)
}
}
}
}

/**
* Iterates through all features using a callback function.
*
Expand Down Expand Up @@ -212,6 +251,31 @@ gdal.LayerFeatures.prototype.forEach = function (callback) {
*/
gdal.LayerFeatures.prototype.map = defaultMap

/**
* Iterates through all features using an iterator
*
* @example
* ```
* for (const feature of layer.features) {
* }```
*
* @for gdal.LayerFeatures
* @method Symbol.iterator
*/
gdal.LayerFeatures.prototype[Symbol.iterator]= function defaultIterator() {
let feature

return {
next: () => {
feature = feature ? this.next() : this.first()
return {
done: !feature,
value: feature
}
}
}
}

/**
* Iterates through all fields using a callback function.
*
Expand Down Expand Up @@ -297,6 +361,19 @@ gdal.LayerFields.prototype.forEach = defaultForEach
*/
gdal.LayerFields.prototype.map = defaultMap

/**
* Iterates through all field definitions using an iterator
*
* @example
* ```
* for (const curve of layer.fields) {
* }```
*
* @for gdal.LayerFields
* @method Symbol.iterator
*/
gdal.LayerFields.prototype[Symbol.iterator] = defaultIterator

/**
* Iterates through all layers using a callback function.
*
Expand Down Expand Up @@ -326,6 +403,19 @@ gdal.DatasetLayers.prototype.forEach = defaultForEach
*/
gdal.DatasetLayers.prototype.map = defaultMap

/**
* Iterates through all layers using an iterator
*
* @example
* ```
* for (const curve of dataset.layers) {
* }```
*
* @for gdal.DatasetLayers
* @method Symbol.iterator
*/
gdal.DatasetLayers.prototype[Symbol.iterator] = defaultIterator

/**
* Iterates through all field definitions using a callback function.
*
Expand All @@ -345,7 +435,7 @@ gdal.FeatureDefnFields.prototype.forEach = defaultForEach
*
* @example
* ```
* var result = dataset.layers.map(function(field, i) {
* var result = featureDefn.map(function(field, i) {
* return value;
* });```
*
Expand All @@ -355,6 +445,19 @@ gdal.FeatureDefnFields.prototype.forEach = defaultForEach
*/
gdal.FeatureDefnFields.prototype.map = defaultMap

/**
* Iterates through all field definitions using an iterator
*
* @example
* ```
* for (const defn of featureDefn) {
* }```
*
* @for gdal.FeatureDefnFields
* @method Symbol.iterator
*/
gdal.FeatureDefnFields.prototype[Symbol.iterator] = defaultIterator

/**
* Iterates through all rings using a callback function.
*
Expand All @@ -378,12 +481,25 @@ gdal.PolygonRings.prototype.forEach = defaultForEach
* return value;
* });```
*
* @for gdal.LineStringPoints
* @for gdal.PolygonRings
* @method map
* @param {Function} callback The callback to be called with each {{#crossLink "gdal.LineString"}}LineString{{/crossLink}}
*/
gdal.PolygonRings.prototype.map = defaultMap

/**
* Iterates through all rings using an iterator
*
* @example
* ```
* for (const ring of polygon.rings) {
* }```
*
* @for gdal.PolygonRings
* @method Symbol.iterator
*/
gdal.PolygonRings.prototype[Symbol.iterator] = defaultIterator

/**
* Iterates through all points using a callback function.
*
Expand Down Expand Up @@ -413,6 +529,61 @@ gdal.LineStringPoints.prototype.forEach = defaultForEach
*/
gdal.LineStringPoints.prototype.map = defaultMap

/**
* Iterates through all points using an iterator
*
* @example
* ```
* for (const point of lineString.points) {
* }```
*
* @for gdal.LineStringPoints
* @method Symbol.iterator
*/
gdal.LineStringPoints.prototype[Symbol.iterator] = defaultIterator

/**
* Iterates through all curves using a callback function.
*
* @example
* ```
* compoundCurve.curves.forEach(function(curve, i) { ... });```
*
* @for gdal.CompoundCurves
* @method forEach
* @param {Function} callback The callback to be called with each {{#crossLink "gdal.SimpleCurve"}}SimpleCurve{{/crossLink}}
*/
gdal.CompoundCurves.prototype.forEach = defaultForEach

/**
* Iterates through all curves using a callback function and builds
* an array of the returned values.
*
* @example
* ```
* var result = compoundCurves.curves.map(function(curve, i) {
* return value;
* });```
*
* @for gdal.CompoundCurves
* @method map
* @param {Function} callback The callback to be called with each {{#crossLink "gdal.SimpleCurve"}}SimpleCurve{{/crossLink}}
*/
gdal.CompoundCurves.prototype.map = defaultMap

/**
* Iterates through all curves using an iterator
*
* @example
* ```
* for (const curve of compoundCurves.curves) {
* }
*
* @for gdal.CompoundCurves
* @method Symbol.iterator
*/
gdal.CompoundCurves.prototype[Symbol.iterator] = defaultIterator

/**
* Iterates through all child geometries using a callback function.
*
Expand Down Expand Up @@ -471,6 +642,19 @@ gdal.RasterBandOverviews.prototype.forEach = defaultForEach
*/
gdal.RasterBandOverviews.prototype.map = defaultMap

/**
* Iterates through all overview using an iterator
*
* @example
* ```
* for (const overview of band.overviews) {
* }
*
* @for gdal.RasterBandOverviews
* @method Symbol.iterator
*/
gdal.RasterBandOverviews.prototype[Symbol.iterator] = defaultIterator

/**
* Iterates through all registered drivers using a callback function.
*
Expand Down Expand Up @@ -500,6 +684,19 @@ gdal.GDALDrivers.prototype.forEach = defaultForEach
*/
gdal.GDALDrivers.prototype.map = defaultMap

/**
* Iterates through all drivers using an iterator
*
* @example
* ```
* for (const curve of gdal.drivers) {
* }
*
* @for gdal.GDALDrivers
* @method Symbol.iterator
*/
gdal.GDALDrivers.prototype[Symbol.iterator] = defaultIterator

/**
* Outputs all geometries as a regular javascript array.
*
Expand Down Expand Up @@ -822,10 +1019,13 @@ gdal.LayerFields.prototype.fromObject = function (obj, approx_ok) {

gdal.Point.wkbType = gdal.wkbPoint
gdal.LineString.wkbType = gdal.wkbLineString
gdal.CircularString.wkbType = gdal.wkbCircularString
gdal.LinearRing.wkbType = gdal.wkbLinearRing
gdal.CompoundCurve.wkbType = gdal.wkbCompoundCurve
gdal.Polygon.wkbType = gdal.wkbPolygon
gdal.MultiPoint.wkbType = gdal.wkbMultiPoint
gdal.MultiLineString.wkbType = gdal.wkbMultiLineString
gdal.MultiCurve.wkbType = gdal.wkbMultiCurve
gdal.MultiPolygon.wkbType = gdal.wkbMultiPolygon
gdal.GeometryCollection.wkbType = gdal.wkbGeometryCollection

Expand Down
Loading

0 comments on commit cbe4566

Please sign in to comment.