shp

package
v1.0.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 21, 2021 License: Apache-2.0 Imports: 10 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type BoundingBox

type BoundingBox struct {
	MinX float64
	MinY float64
	MaxX float64
	MaxY float64
}

BoundingBox of the shape file.

func DecodeBoundingBox

func DecodeBoundingBox(buf []byte) (BoundingBox, error)

DecodeBoundingBox decodes the bounding box coordinates.

func DecodeBoundingBoxP

func DecodeBoundingBoxP(buf []byte, precision uint) (BoundingBox, error)

DecodeBoundingBoxP decodes the bounding box coordinates with a specified precision.

func (BoundingBox) String

func (b BoundingBox) String() string

type Error

type Error struct {
	// contains filtered or unexported fields
}

Error describes an error that occured when parsing a shape.

func NewError

func NewError(err error, recordNum uint32) Error

NewError returns an attached to record number.

func (Error) Error

func (e Error) Error() string
type Header struct {
	FileLength  uint32
	Version     uint32
	ShapeType   ShapeType
	BoundingBox BoundingBox
}

Header represents a shp header.

func DecodeHeader

func DecodeHeader(buf []byte, opts ...Option) (Header, error)

DecodeHeader decodes a shp header.

type Option

type Option func(*config)

Option funcs can be passed to NewScanner().

func PointPrecision

func PointPrecision(p uint) Option

PointPrecision sets the precision of coordinates.

type Part

type Part []Point

Part is a sequence of Points.

type Point

type Point struct {
	r2.Point
	// contains filtered or unexported fields
}

Point is a single pair of X and Y coordinates.

func DecodePoint

func DecodePoint(buf []byte, num uint32) (Point, error)

DecodePoint decodes a single point shape.

func DecodePointP

func DecodePointP(buf []byte, num uint32, precision uint) (Point, error)

DecodePointP decodes a single point shape with specified precision.

func MakePoint

func MakePoint(x, y float64) Point

MakePoint creates a new Point for the provided coordinate.

func (Point) GeoJSONFeature

func (p Point) GeoJSONFeature() *geojson.Feature

GeoJSONFeature creates a GeoJSON Point from a Shapefile Point.

func (Point) RecordNumber

func (p Point) RecordNumber() uint32

RecordNumber returns the position in the shape file.

func (Point) String

func (p Point) String() string

func (Point) Type

func (p Point) Type() ShapeType

Type is PointType.

func (Point) Validate

func (p Point) Validate(v Validator) error

Validate the Point by checking that it is within the shp file bounding box.

type Polygon

type Polygon Polyline

Polygon has the same syntax as a Polyline, but the parts should be unbroken rings.

func DecodePolygon

func DecodePolygon(buf []byte, num uint32) (Polygon, error)

DecodePolygon decodes a single polygon shape, but does not validate its complicance with the spec.

func DecodePolygonP

func DecodePolygonP(buf []byte, num uint32, precision uint) (Polygon, error)

DecodePolygonP decodes a single polygon shape with the specified precision, but does not validate its complicance with the spec.

func (Polygon) GeoJSONFeature

func (p Polygon) GeoJSONFeature() *geojson.Feature

GeoJSONFeature creates a GeoJSON Polygon from a Shapefile Polygon.

func (Polygon) RecordNumber

func (p Polygon) RecordNumber() uint32

RecordNumber returns the position in the shape file.

func (Polygon) Type

func (p Polygon) Type() ShapeType

Type is PolygonType.

func (Polygon) Validate

func (p Polygon) Validate(v Validator) error

Validate the Polygon.

type Polyline

type Polyline struct {
	BoundingBox BoundingBox
	Parts       []Part
	// contains filtered or unexported fields
}

Polyline is an ordered set of verticies that consists of one or more parts, where a part is one or more Point.

func DecodePolyline

func DecodePolyline(buf []byte, num uint32) (Polyline, error)

DecodePolyline parses a single polyline shape, but does not validate its complicance with the spec.

func DecodePolylineP

func DecodePolylineP(buf []byte, num uint32, precision uint) (Polyline, error)

DecodePolylineP parses a single polyline shape with the specified precision, but does not validate its complicance with the spec.

func (Polyline) GeoJSONFeature

func (p Polyline) GeoJSONFeature() *geojson.Feature

GeoJSONFeature creates a GeoJSON MultiLineString from a Shapefile Polyline.

func (Polyline) RecordNumber

func (p Polyline) RecordNumber() uint32

RecordNumber returns the position in the shape file.

func (Polyline) Type

func (p Polyline) Type() ShapeType

Type is PolylineType.

func (Polyline) Validate

func (p Polyline) Validate(v Validator) error

Validate the Polyline.

type Scanner

type Scanner struct {
	// contains filtered or unexported fields
}

Scanner parses a shp file.

func NewScanner

func NewScanner(r io.Reader, opts ...Option) *Scanner

NewScanner creates a new Scanner for the supplied source.

func (*Scanner) AddOptions

func (s *Scanner) AddOptions(opts ...Option)

AddOptions to scanner after creation.

func (*Scanner) Err

func (s *Scanner) Err() error

Err returns the first error encountered when parsing records. It should be called after calling the Shape method for the last time.

func (*Scanner) Header

func (s *Scanner) Header() (Header, error)

Header parses the shp file header.

func (*Scanner) Scan

func (s *Scanner) Scan() error

Scan starts reading the shp file. Shapes can be accessed from the Shape method. An error is returned if there's a problem parsing the header. Errors that are encountered when parsing records must be checked with the Err method.

func (*Scanner) Shape

func (s *Scanner) Shape() Shape

Shape returns each shape found in the shp file. nil is returned once the last record has been read, or an error occurs - the Err method should be used to check for an error at this point.

func (*Scanner) Validator

func (s *Scanner) Validator() (Validator, error)

Validator returns a Validator that can be used to validate Shapes using the Validate method.

type Shape

type Shape interface {
	Type() ShapeType
	RecordNumber() uint32
	Validate(Validator) error
	GeoJSONFeature() *geojson.Feature
	// contains filtered or unexported methods
}

Shape provides common information for all shapes of any type.

type ShapeType

type ShapeType uint

ShapeType represents a shape type in the shp file.

const (
	// Null shapes are allowed in any shp file, regardless of the type specified in the header.
	NullType ShapeType = 0

	PointType       ShapeType = 1
	PolylineType    ShapeType = 3
	PolygonType     ShapeType = 5
	MultiPointType  ShapeType = 8
	PointZType      ShapeType = 11
	PolylineZType   ShapeType = 13
	PolygonZType    ShapeType = 15
	MultiPointZType ShapeType = 18
	PointMType      ShapeType = 21
	PolylineMType   ShapeType = 23
	PolygonMType    ShapeType = 25
	MultiPointMType ShapeType = 28
	MultiPatchType  ShapeType = 31
)

Valid shape types. All shapes in a single shp file must be of the same type.

func (ShapeType) String

func (t ShapeType) String() string

type Shapes

type Shapes []Shape

Shapes represents a collection of shapes.

func (Shapes) BoundingBox

func (s Shapes) BoundingBox() BoundingBox

BoundingBox returns the bounding box that encompasses all shapes.

type Validator

type Validator struct {
	// contains filtered or unexported fields
}

Validator is used to validate shapes inside a shp file.

func MakeValidator

func MakeValidator(box BoundingBox) (Validator, error)

MakeValidator creates a new Validator based on the constraints of a particular shp file.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL