Documentation
¶
Overview ¶
Package geojson 将日月食和月掩地理结果编码为 RFC 7946 GeoJSON FeatureCollections。 坐标是 WGS84 经度和纬度,单位为度;地图投影和样式由应用处理。 Package geojson encodes eclipse and lunar-occultation geographic results as RFC 7946 GeoJSON FeatureCollections. Coordinates are WGS84 longitude and latitude in degrees; map projection and styling remain application concerns.
每个要素都包含 event 和 role 属性。带时间的 MultiLineString 要素还包含与坐标段对齐的嵌套 times 数组。 Times 编码为 UTC RFC 3339 字符串;路径采样由上游日月食和月掩选项控制后再传入本包。 WithTimeMarkers 变体还会追加 role 为 time-marker 的 Point 要素,标签按请求地点格式化。 Every feature has event and role properties. Timed MultiLineString features also contain a nested times array aligned with their coordinate segments. Times are encoded as UTC RFC 3339 strings. Path sampling is controlled by the source eclipse and occultation options before values reach this package. The WithTimeMarkers variants additionally append Point Features whose role is time-marker and whose label is formatted for the requested location.
Index ¶
- func MarshalLunarEclipse(info eclipsecore.LunarEclipseInfo, boundaryPoints int) ([]byte, error)
- func MarshalLunarEclipseWithTimeMarkers(info eclipsecore.LunarEclipseInfo, boundaryPoints int, ...) ([]byte, error)
- func MarshalPlanetOccultation(path moon.PlanetOccultationPath) ([]byte, error)
- func MarshalPlanetOccultationWithTimeMarkers(path moon.PlanetOccultationPath, options TimeMarkerOptions) ([]byte, error)
- func MarshalSolarEclipse(partial eclipsecore.SolarEclipsePartialFootprintsInfo, ...) ([]byte, error)
- func MarshalSolarEclipseWithTimeMarkers(partial eclipsecore.SolarEclipsePartialFootprintsInfo, ...) ([]byte, error)
- func MarshalStarOccultation(path moon.StarOccultationPath) ([]byte, error)
- func MarshalStarOccultationWithTimeMarkers(path moon.StarOccultationPath, options TimeMarkerOptions) ([]byte, error)
- type TimeMarkerOptions
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func MarshalLunarEclipse ¶
func MarshalLunarEclipse(info eclipsecore.LunarEclipseInfo, boundaryPoints int) ([]byte, error)
MarshalLunarEclipse 将月食 P1/P4 可见半球和地平线边界编码为 GeoJSON。 MarshalLunarEclipse encodes the P1/P4 visible hemispheres and horizon boundaries as GeoJSON. boundaryPoints 小于等于零时使用 360;其他值限制在 [12, 1440]。 boundaryPoints values <= 0 use 360; other values are clamped to [12, 1440].
func MarshalLunarEclipseWithTimeMarkers ¶
func MarshalLunarEclipseWithTimeMarkers( info eclipsecore.LunarEclipseInfo, boundaryPoints int, options TimeMarkerOptions, ) ([]byte, error)
MarshalLunarEclipseWithTimeMarkers 编码月食,并沿半影开始到结束的月下点轨迹追加 Point 要素。 MarshalLunarEclipseWithTimeMarkers encodes a lunar eclipse and adds Point Features along the sublunar track from penumbral start through end. 已有要素保持不变;标记标签使用 options.Location,时间值保持 UTC。 Existing features are unchanged; marker labels use options.Location while time values stay UTC.
func MarshalPlanetOccultation ¶
func MarshalPlanetOccultation(path moon.PlanetOccultationPath) ([]byte, error)
MarshalPlanetOccultation 将月掩行星的部分掩、全掩和中心线编码为 GeoJSON。 MarshalPlanetOccultation encodes partial, total, and center-line planetary occultation geometry as GeoJSON.
func MarshalPlanetOccultationWithTimeMarkers ¶
func MarshalPlanetOccultationWithTimeMarkers( path moon.PlanetOccultationPath, options TimeMarkerOptions, ) ([]byte, error)
MarshalPlanetOccultationWithTimeMarkers 编码行星月掩,并沿中心线按固定间隔追加 Point 要素。 MarshalPlanetOccultationWithTimeMarkers encodes a planetary occultation and adds Point Features at regular intervals along its center line.
func MarshalSolarEclipse ¶
func MarshalSolarEclipse( partial eclipsecore.SolarEclipsePartialFootprintsInfo, central *eclipsecore.SolarEclipsePath, ) ([]byte, error)
MarshalSolarEclipse 将日食半影足迹和可选中心食带编码为 GeoJSON。 MarshalSolarEclipse encodes penumbral footprints and an optional central path as GeoJSON.
Example ¶
package main
import (
"encoding/json"
"fmt"
"time"
"b612.me/astro/eclipse"
"b612.me/astro/geojson"
)
func main() {
date := time.Date(2024, time.April, 8, 0, 0, 0, 0, time.UTC)
partial, ok := eclipse.SolarEclipsePartialFootprints(
date,
eclipse.SolarEclipsePartialFootprintOptions{
Step: 10 * time.Minute,
BoundaryPoints: 180,
},
)
if !ok {
return
}
central, hasCentral := eclipse.SolarEclipseCentralPath(
date,
eclipse.SolarEclipsePathOptions{
Step: time.Minute,
TargetSpacingKM: 20,
},
)
var centralPath *eclipse.SolarEclipsePath
if hasCentral {
centralPath = ¢ral
}
data, err := geojson.MarshalSolarEclipse(partial, centralPath)
fmt.Println(err == nil, json.Valid(data))
}
Output: true true
func MarshalSolarEclipseWithTimeMarkers ¶
func MarshalSolarEclipseWithTimeMarkers( partial eclipsecore.SolarEclipsePartialFootprintsInfo, central *eclipsecore.SolarEclipsePath, options TimeMarkerOptions, ) ([]byte, error)
MarshalSolarEclipseWithTimeMarkers 编码日食,并沿中心线按固定间隔追加 Point 要素;已有要素不变,标记标签使用 options.Location,时间值保持 UTC。 MarshalSolarEclipseWithTimeMarkers encodes a solar eclipse and adds Point Features at regular intervals along the central line. Existing features are unchanged; marker labels use options.Location while time values stay UTC.
Example ¶
package main
import (
"encoding/json"
"fmt"
"time"
"b612.me/astro/eclipse"
"b612.me/astro/geojson"
)
func main() {
date := time.Date(2024, time.April, 8, 0, 0, 0, 0, time.UTC)
partial, ok := eclipse.SolarEclipsePartialFootprints(
date,
eclipse.SolarEclipsePartialFootprintOptions{Step: 20 * time.Minute, BoundaryPoints: 36},
)
if !ok {
return
}
central, ok := eclipse.SolarEclipseCentralPath(
date,
eclipse.SolarEclipsePathOptions{Step: 5 * time.Minute},
)
if !ok {
return
}
data, err := geojson.MarshalSolarEclipseWithTimeMarkers(
partial,
¢ral,
geojson.TimeMarkerOptions{Step: 30 * time.Minute, Location: time.FixedZone("CST", 8*60*60)},
)
fmt.Println(err == nil, json.Valid(data))
}
Output: true true
func MarshalStarOccultation ¶
func MarshalStarOccultation(path moon.StarOccultationPath) ([]byte, error)
MarshalStarOccultation 将月掩恒星的全球掩带和中心线编码为 GeoJSON。 MarshalStarOccultation encodes a global stellar occultation band and center line as GeoJSON.
func MarshalStarOccultationWithTimeMarkers ¶
func MarshalStarOccultationWithTimeMarkers( path moon.StarOccultationPath, options TimeMarkerOptions, ) ([]byte, error)
MarshalStarOccultationWithTimeMarkers 编码恒星月掩,并沿中心线按固定间隔追加 Point 要素。 MarshalStarOccultationWithTimeMarkers encodes a stellar occultation and adds Point Features at regular intervals along its center line.
Types ¶
type TimeMarkerOptions ¶
type TimeMarkerOptions struct {
// Step 是时间标记之间的间隔;零值使用 30 分钟。
// Step is the interval between time markers; zero uses 30 minutes.
Step time.Duration
// Location 是格式化 HH:MM 标签时使用的时区;nil 使用 UTC。
// Location is the timezone used to format HH:MM labels; nil uses UTC.
Location *time.Location
}
TimeMarkerOptions 控制供地图客户端绘制路径时间标签的可选 Point Feature。 TimeMarkerOptions controls optional Point Features used by map clients to draw time labels along a moving event path. Step 控制标记间隔;零值使用 30 分钟,并对齐到下一个本地整点边界。 Step controls the marker interval; zero uses 30 minutes and aligns markers to the next local clock boundary. Location 控制 HH:MM 标签,默认 UTC;底层 time 属性仍为 UTC RFC 3339。 Location controls the HH:MM label and defaults to UTC. The underlying time property remains UTC RFC 3339. 正 Step 至少为一分钟,单次导出最多 1440 个标记。 Positive Step values must be at least one minute, and one export is limited to 1440 markers.