parser

package
v0.100.0 Latest Latest
Warning

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

Go to latest
Published: Oct 19, 2025 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AttributeCodeToString

func AttributeCodeToString(code int) string

AttributeCodeToString converts S-57 numeric attribute code to string acronym S-57 Appendix A Chapter 2: Attribute Catalogue

func IsSupported

func IsSupported(code int) bool

IsSupported checks if an object class code is valid All object classes defined in S-57 standard are "supported" for parsing The question is whether we have rendering logic for them (deferred to later iterations)

func ObjectClassToInt

func ObjectClassToInt(code string) (int, error)

ObjectClassToInt converts string code to numeric object class S-57 object classes are identified by numeric codes in the binary data

func ObjectClassToString

func ObjectClassToString(code int) (string, error)

ObjectClassToString converts S-57 numeric object class to string code The object class codes are read from the S-57 file's FRID records and mapped using the S-57 Object Catalogue S-57 Appendix A: Object Catalogue

func ValidateCoordinate

func ValidateCoordinate(lat, lon float64) error

ValidateCoordinate validates a single coordinate pair S-57 coordinates must be within valid geographic bounds

func ValidateFeature

func ValidateFeature(feature *Feature) error

ValidateFeature validates a feature per S-57 rules

func ValidateGeometry

func ValidateGeometry(geometry *Geometry) error

ValidateGeometry validates geometry per S-57 spatial rules S-57 §7.3: Geometry validation rules

Types

type Chart

type Chart struct {
	Features []Feature // Public - array of extracted features
	// contains filtered or unexported fields
}

Chart represents a complete S-57 Electronic Navigational Chart. This is the top-level structure returned by the parser.

Reference: S-57 Part 3 §7 (31Main.pdf p3.31): Structure implementation showing how datasets are composed of metadata and feature records.

func (*Chart) ApplicationProfile

func (c *Chart) ApplicationProfile() string

ApplicationProfile returns human-readable application profile.

func (*Chart) Comment

func (c *Chart) Comment() string

Comment returns the metadata comment field.

func (*Chart) CompilationScale

func (c *Chart) CompilationScale() int32

CompilationScale returns the compilation scale from the DSPM record. S-57 §7.3.2.1 CSCL field: scale denominator (e.g., 50000 for 1:50,000).

func (*Chart) CoordinateUnits

func (c *Chart) CoordinateUnits() int

CoordinateUnits returns the coordinate units from the DSPM record. S-57 §7.3.2.1 COUN field: 1=lat/lon, 2=eastings/northings.

func (*Chart) DatasetName

func (c *Chart) DatasetName() string

DatasetName returns the chart's dataset name (cell identifier).

func (*Chart) Edition

func (c *Chart) Edition() string

Edition returns the chart's edition number.

func (*Chart) ExchangePurpose

func (c *Chart) ExchangePurpose() string

ExchangePurpose returns human-readable exchange purpose ("New" or "Revision").

func (*Chart) HorizontalDatum

func (c *Chart) HorizontalDatum() int

HorizontalDatum returns the horizontal datum code from the DSPM record. S-57 §7.3.2.1 HDAT field: 2=WGS-84 (most common).

func (*Chart) IntendedUsage

func (c *Chart) IntendedUsage() int

IntendedUsage returns the intended usage (navigational purpose) code.

Values per S-57 specification:

1 = Overview, 2 = General, 3 = Coastal, 4 = Approach, 5 = Harbour, 6 = Berthing

func (*Chart) IssueDate

func (c *Chart) IssueDate() string

IssueDate returns the issue date (YYYYMMDD).

func (*Chart) ProducingAgency

func (c *Chart) ProducingAgency() int

ProducingAgency returns the producing agency code.

func (*Chart) ProductSpecification

func (c *Chart) ProductSpecification() string

ProductSpecification returns human-readable product spec ("ENC" or "ODD").

func (*Chart) S57Edition

func (c *Chart) S57Edition() string

S57Edition returns the S-57 standard edition used (e.g., "03.1").

func (*Chart) UpdateDate

func (c *Chart) UpdateDate() string

UpdateDate returns the update application date (YYYYMMDD).

func (*Chart) UpdateNumber

func (c *Chart) UpdateNumber() string

UpdateNumber returns the chart's update number.

type ErrInvalidCoordinate

type ErrInvalidCoordinate struct {
	Lat, Lon float64
}

ErrInvalidCoordinate indicates coordinate out of valid bounds

func (*ErrInvalidCoordinate) Error

func (e *ErrInvalidCoordinate) Error() string

type ErrInvalidGeometry

type ErrInvalidGeometry struct {
	Type   GeometryType
	Reason string
}

ErrInvalidGeometry indicates geometry violates S-57 rules

func (*ErrInvalidGeometry) Error

func (e *ErrInvalidGeometry) Error() string

type ErrInvalidSpatialRecord

type ErrInvalidSpatialRecord struct {
	SpatialID int64
	Reason    string
}

ErrInvalidSpatialRecord indicates spatial record is not of expected type

func (*ErrInvalidSpatialRecord) Error

func (e *ErrInvalidSpatialRecord) Error() string

type ErrMissingSpatialRecord

type ErrMissingSpatialRecord struct {
	FeatureID int64
	SpatialID int64
}

ErrMissingSpatialRecord indicates FSPT pointer references non-existent spatial record

func (*ErrMissingSpatialRecord) Error

func (e *ErrMissingSpatialRecord) Error() string

type ErrUnknownObjectClass

type ErrUnknownObjectClass struct {
	Code int
}

ErrUnknownObjectClass indicates unsupported S-57 object class

func (*ErrUnknownObjectClass) Error

func (e *ErrUnknownObjectClass) Error() string

type Feature

type Feature struct {
	// ID is the unique feature identifier from the FRID record
	ID int64
	// ObjectClass is the S-57 object class code (e.g., "DEPCNT", "DEPARE", "BOYCAR")
	ObjectClass string
	// Geometry is the spatial representation of the feature
	Geometry Geometry
	// Attributes contains feature attributes as key-value pairs
	// Common attributes: DRVAL1 (depth), COLOUR (color), OBJNAM (name)
	Attributes map[string]interface{}
}

Feature represents a navigational object extracted from S-57 chart data S-57 §2.1: Feature objects contain geometric and attribute information

type Geometry

type Geometry struct {
	// Type is the geometry type (Point, LineString, or Polygon)
	Type GeometryType
	// Coordinates is an array of [longitude, latitude] pairs
	// Per GeoJSON convention: [lon, lat]
	Coordinates [][]float64
}

Geometry represents the spatial representation of a feature S-57 §7.3: Spatial record structure

type GeometryType

type GeometryType int

GeometryType represents the type of geometry for a feature

const (
	// GeometryTypePoint represents a single point location
	GeometryTypePoint GeometryType = iota
	// GeometryTypeLineString represents a line composed of connected points
	GeometryTypeLineString
	// GeometryTypePolygon represents a closed polygon area
	GeometryTypePolygon
)

func (GeometryType) String

func (g GeometryType) String() string

String returns the string representation of the geometry type

type ParseOptions

type ParseOptions struct {
	// SkipUnknownFeatures: if true, skip features with unknown object classes
	// Default: false (return error on unknown types)
	SkipUnknownFeatures bool

	// ValidateGeometry: if true, validate all coordinates and geometry rules
	// Default: true
	ValidateGeometry bool

	// ObjectClassFilter: if non-empty, only extract these object classes
	// Empty means extract all supported types
	ObjectClassFilter []string

	// ApplyUpdates: if true, automatically discover and apply update files (.001, .002, etc.)
	// Default: true
	ApplyUpdates bool

	// Fs is the filesystem to use for reading files
	// If nil, the OS filesystem is used
	Fs afero.Fs
}

ParseOptions configures parsing behavior

func DefaultParseOptions

func DefaultParseOptions() ParseOptions

DefaultParseOptions returns parse options with defaults

type Parser

type Parser interface {
	// Parse reads an S-57 file and returns extracted chart
	// Returns error if file cannot be read or parsed
	Parse(filename string) (*Chart, error)

	// ParseWithOptions parses with custom options
	ParseWithOptions(filename string, opts ParseOptions) (*Chart, error)

	// SupportedObjectClasses returns list of supported S-57 object classes
	SupportedObjectClasses() []string
}

Parser parses S-57 ENC files and extracts features.

S-57 defines an "exchange set" as a collection of files for transferring hydrographic data. Each file contains records (metadata, features, spatial data) structured per ISO 8211. This parser reads the ISO 8211 structure and interprets it according to S-57 semantics.

References:

  • S-57 Part 1 (31Main.pdf p1.1): Definition of "exchange set"
  • S-57 Part 3 §7 (31Main.pdf p3.31): Complete record and field structure specification

func DefaultParser

func DefaultParser() (Parser, error)

DefaultParser returns parser with default options

func NewParser

func NewParser() Parser

NewParser creates a new S-57 parser

type UpdateInstruction

type UpdateInstruction int

UpdateInstruction represents the RUIN (Record Update Instruction) field values S-57 Part 3 §8.4.2.2 and §8.4.3.2

const (
	// UpdateInsert indicates a record should be inserted (RUIN = 1)
	UpdateInsert UpdateInstruction = 1

	// UpdateDelete indicates a record should be deleted (RUIN = 2)
	UpdateDelete UpdateInstruction = 2

	// UpdateModify indicates a record should be modified (RUIN = 3)
	UpdateModify UpdateInstruction = 3
)

Jump to

Keyboard shortcuts

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