shapefile

package module
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Feb 6, 2024 License: MIT Imports: 21 Imported by: 0

README

go-shapefile

GoDoc

Package go-shapefile provides a native Go reader for ESRI Shapefiles.

License

MIT

Documentation

Overview

Package shapefile reads ESRI Shapefiles.

See https://support.esri.com/en/white-paper/279.

Package shapefile reads ESRI Shapefiles.

See https://support.esri.com/en/white-paper/279.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NoData

func NoData(x float64) bool

NoData returns if x represents no data.

func TrimTrailingZeros

func TrimTrailingZeros(data []byte) []byte

TrimTrailingZeros trims any trailing zero bytes from data.

Types

type CPG

type CPG struct {
	Charset string
}

CPG a CPG is a .cpg file.

func ReadCPG

func ReadCPG(r io.Reader, _ int64) (*CPG, error)

ReadCPG reads a CPG from an io.Reader.

func ReadCPGZipFile

func ReadCPGZipFile(zipFile *zip.File) (*CPG, error)

ReadCPGZipFile reads a CPG from a *zip.File.

type DBF

type DBF struct {
	DBFHeader
	FieldDescriptors []*DBFFieldDescriptor
	Records          [][]any
}

A DBF is a dBase III PLUS table.

See http://web.archive.org/web/20150323061445/http://ulisse.elettra.trieste.it/services/doc/dbase/DBFstruct.htm. See https://www.clicketyclick.dk/databases/xbase/format/dbf.html.

func ReadDBF

func ReadDBF(r io.Reader, _ int64, options *ReadDBFOptions) (*DBF, error)

ReadDBF reads a DBF from an io.Reader.

func ReadDBFZipFile

func ReadDBFZipFile(zipFile *zip.File, options *ReadDBFOptions) (*DBF, error)

ReadDBFZipFile reads a DBF from a *zip.File.

func (*DBF) Record

func (d *DBF) Record(i int) map[string]any

Record returns the ith record.

type DBFFieldDescriptor

type DBFFieldDescriptor struct {
	Name         string
	Type         byte
	Length       int
	DecimalCount int
	WorkAreaID   byte
	SetFields    byte
}

A DBFFieldDescriptor describes a DBF field.

func (*DBFFieldDescriptor) ParseRecord

func (d *DBFFieldDescriptor) ParseRecord(data []byte, decoder *encoding.Decoder) (any, error)

ParseRecord parses a record from data.

type DBFHeader

type DBFHeader struct {
	Version    int
	Memo       bool
	DBT        bool
	LastUpdate time.Time
	Records    int
	HeaderSize int
	RecordSize int
}

A DBFHeader is a DBF header.

func ParseDBFHeader

func ParseDBFHeader(data []byte, options *ReadDBFOptions) (*DBFHeader, error)

ParseDBFHeader parses a DBFHeader from data.

type DBFMemo

type DBFMemo string

A DBFMemo is a DBF memo.

type DBFRecord

type DBFRecord = []any

type PRJ

type PRJ struct {
	Projection string
}

A PRJ is a .prj file.

func ReadPRJ

func ReadPRJ(r io.Reader, _ int64) (*PRJ, error)

ReadPRJ reads a PRJ from an io.Reader.

func ReadPRJZipFile

func ReadPRJZipFile(zipFile *zip.File) (*PRJ, error)

ReadPRJZipFile reads a PRJ from a *zip.File.

type ReadDBFOptions

type ReadDBFOptions struct {
	MaxHeaderSize int
	MaxRecordSize int
	MaxRecords    int
	Charset       string
}

ReadDBFOptions are options to ReadDBF.

type ReadSHPOptions

type ReadSHPOptions struct {
	MaxParts      int
	MaxPoints     int
	MaxRecordSize int
}

ReadSHPOptions are options for ReadSHP.

type ReadShapefileOptions

type ReadShapefileOptions struct {
	DBF *ReadDBFOptions
	SHP *ReadSHPOptions
}

ReadShapefileOptions are options to ReadFS.

type SHP

type SHP struct {
	SHxHeader
	Records []*SHPRecord
}

A SHP is a .shp file.

func ReadSHP

func ReadSHP(r io.Reader, fileLength int64, options *ReadSHPOptions) (*SHP, error)

ReadSHP reads a SHP from an io.Reader.

func ReadSHPZipFile

func ReadSHPZipFile(zipFile *zip.File, options *ReadSHPOptions) (*SHP, error)

ReadSHPZipFile reads a *SHP from a *zip.File.

func (*SHP) Record

func (s *SHP) Record(i int) geom.T

Record returns the ith geometry.

type SHPRecord

type SHPRecord struct {
	Number        int
	ContentLength int
	ShapeType     ShapeType
	Bounds        *geom.Bounds
	Geom          geom.T
}

A SHPRecord is a record in a SHP file.

func ReadSHPRecord

func ReadSHPRecord(r io.Reader, options *ReadSHPOptions) (*SHPRecord, error)

ReadSHPRecord reads the next *SHPRecord from r.

type SHX

type SHX struct {
	SHxHeader
	Records []SHXRecord
}

An SHX is a .shx file.

func ReadSHX

func ReadSHX(r io.Reader, size int64) (*SHX, error)

ReadSHX reads a SHX from an io.Reader.

func ReadSHXZipFile

func ReadSHXZipFile(zipFile *zip.File) (*SHX, error)

ReadSHXZipFile reads a SHX from a *zip.File.

type SHXRecord

type SHXRecord struct {
	Offset        int
	ContentLength int
}

An SHXRecord is a record in a SHX.

func ParseSHXRecord

func ParseSHXRecord(data []byte) SHXRecord

ParseSHXRecord parses a SHXRecord from data.

type SHxHeader

type SHxHeader struct {
	ShapeType ShapeType
	Bounds    *geom.Bounds
}

A SHxHeader is header of a .shp or .shx file.

type Scanner

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

Scanner ...

func NewScanner

func NewScanner(
	readers map[string]io.ReadCloser,
	sizes map[string]int64,
	options *ReadShapefileOptions,
) (*Scanner, error)

NewScanner Create a new scanner.

func NewScannerFromBasename

func NewScannerFromBasename(basename string, options *ReadShapefileOptions) (*Scanner, error)

NewScannerFromBasename reads files based of Basename and create a scanner.

func NewScannerFromZipFile

func NewScannerFromZipFile(name string, options *ReadShapefileOptions) (*Scanner, error)

NewScannerFromZipFile reads a .zip file and create a scanner.

func NewScannerFromZipReader

func NewScannerFromZipReader(zipReader *zip.Reader, options *ReadShapefileOptions) (*Scanner, error)

NewScannerFromZipReader reads a *zip.Reader and create a scanner.

func (Scanner) Charset

func (s Scanner) Charset() string

func (*Scanner) Close

func (s *Scanner) Close() error

func (*Scanner) DBFFieldDescriptors

func (s *Scanner) DBFFieldDescriptors() []*DBFFieldDescriptor

func (*Scanner) DBFHeader

func (s *Scanner) DBFHeader() *DBFHeader

func (*Scanner) Discard

func (s *Scanner) Discard(n int) (int, error)

Discard Discards n records for concurrent scan.

func (Scanner) Error

func (s Scanner) Error() error

func (Scanner) EstimatedRecords

func (s Scanner) EstimatedRecords() int64

func (*Scanner) Next

func (s *Scanner) Next() bool

func (Scanner) Projection

func (s Scanner) Projection() string

func (*Scanner) SHPHeader

func (s *Scanner) SHPHeader() *SHxHeader

func (*Scanner) SHxHeader

func (s *Scanner) SHxHeader() *SHxHeader

func (*Scanner) Scan

func (s *Scanner) Scan() (recordSHP *SHPRecord, recordSHX *SHXRecord, recordDBF DBFRecord)

Scan Scanner records.

func (Scanner) ScannedRecords

func (s Scanner) ScannedRecords() int64

type ScannerDBF

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

func NewScannerDBF

func NewScannerDBF(reader io.ReadCloser, options *ReadDBFOptions) (*ScannerDBF, error)

func (*ScannerDBF) FieldDescriptors

func (s *ScannerDBF) FieldDescriptors() []*DBFFieldDescriptor

func (*ScannerDBF) Scan

func (s *ScannerDBF) Scan() (DBFRecord, error)

type ScannerSHP

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

func NewScannerSHP

func NewScannerSHP(reader io.ReadCloser, size int64, options *ReadSHPOptions) (*ScannerSHP, error)

func (*ScannerSHP) Scan

func (s *ScannerSHP) Scan() (*SHPRecord, error)

type ScannerSHX

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

func NewScannerSHX

func NewScannerSHX(reader io.ReadCloser, size int64) (*ScannerSHX, error)

func (*ScannerSHX) Scan

func (s *ScannerSHX) Scan() (*SHXRecord, error)

type ShapeType

type ShapeType uint

A ShapeType is a shape type.

const (
	ShapeTypeNull        ShapeType = 0
	ShapeTypePoint       ShapeType = 1
	ShapeTypePolyLine    ShapeType = 3
	ShapeTypePolygon     ShapeType = 5
	ShapeTypeMultiPoint  ShapeType = 8
	ShapeTypePointZ      ShapeType = 11
	ShapeTypePolyLineZ   ShapeType = 13
	ShapeTypePolygonZ    ShapeType = 15
	ShapeTypeMultiPointZ ShapeType = 18
	ShapeTypePointM      ShapeType = 21
	ShapeTypePolyLineM   ShapeType = 23
	ShapeTypePolygonM    ShapeType = 25
	ShapeTypeMultiPointM ShapeType = 28
	ShapeTypeMultiPatch  ShapeType = 31
)

Shape types.

type Shapefile

type Shapefile struct {
	DBF *DBF
	PRJ *PRJ
	CPG *CPG
	SHP *SHP
	SHX *SHX
}

A Shapefile is an ESRI Shapefile.

func Read

func Read(basename string, options *ReadShapefileOptions) (*Shapefile, error)

Read reads a Shapefile from basename.

func ReadFS

func ReadFS(fsys fs.FS, basename string, options *ReadShapefileOptions) (*Shapefile, error)

ReadFS reads a Shapefile from fsys with the given basename.

func ReadScanner

func ReadScanner(scanner *Scanner) (*Shapefile, error)

ReadScanner read a scanner and create a shapefile.

func ReadZipFile

func ReadZipFile(name string, options *ReadShapefileOptions) (*Shapefile, error)

ReadZipFile reads a Shapefile from a .zip file.

func ReadZipReader

func ReadZipReader(zipReader *zip.Reader, options *ReadShapefileOptions) (*Shapefile, error)

ReadZipReader reads a Shapefile from a *zip.Reader.

func (*Shapefile) NumRecords

func (s *Shapefile) NumRecords() int

NumRecords returns the number of records in s.

func (*Shapefile) Record

func (s *Shapefile) Record(i int) (map[string]any, geom.T)

Record returns s's ith record's fields and geometry.

Jump to

Keyboard shortcuts

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