xutil

package module
v0.0.0-...-57ba848 Latest Latest
Warning

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

Go to latest
Published: Jan 30, 2023 License: GPL-3.0 Imports: 37 Imported by: 0

README

xutil

install

go get -u github.com/xvill/xutil

usage

package main

import (
	"fmt"

	"github.com/xvill/xutil"
)

func main() {
	g, _ := xutil.FromWKT("POINT(121.44528145 30.96964209)")
	g.Wgs2gcj()
	g.FlipCoordinates()
	fmt.Println(g)

	wktstr := []string{
		"POINT(1 2)",
		"LINESTRING(3 4,10 50,20 25)",
		"POLYGON((30 10, 40 40, 20 40, 10 20, 30 10))",
		"POLYGON((35 10, 45 45, 15 40, 10 20, 35 10),(20 30, 35 35, 30 20, 20 30))", //POLYGON with hole
		"MULTIPOINT (10 40, 40 30, 20 20, 30 10)",
		"MULTILINESTRING((10 10, 20 20, 10 40),(40 40, 30 30, 40 20, 30 10))",
		"MULTIPOLYGON(((30 20, 45 40, 10 40, 30 20)),((15 5, 40 10, 10 20, 5 10, 15 5)))",
		"MULTIPOLYGON(((40 40, 20 45, 45 30, 40 40)),((20 35, 10 30, 10 10, 30 5, 45 20, 20 35),(30 20, 20 15, 20 25, 30 20)))",
	}
	for _, s := range wktstr {
		g, _ := xutil.FromWKT(s)
		fmt.Println(g.GeoJSON())
	}
}

function

func CsvWriteALL(data [][]string, wfile string, comma rune) error {} // 生成CSV
func Sqlldr(timeflag, userid, data, control, baddir string)(rows, badrows int, err error)  {}    // 执行成功返回入库记录数,失败则保留log和data到baddir
func IsFileExist(path string) (isExist, isDir bool, err error) {}    // 文件是否存在
 
func FromWKT(wkt string) (Geo, error){}  // 解析WKT为Geo
func (g Geo) ToWKT() (wkt string) {} // 生成WKT
func (g Geo) GeoJSON() (s string, err error) {}  // 生成GeoJSON
func (g Geo) Lines() []Line {} // 所有线段
func (g Geo) Points() []Point {} // 所有点
func (g Geo) Copy() Geo {} // 复制
func (g Geo) PointFunc(f func(lon, lat float64) (float64, float64)) {} // 对所有点应用函数
func (g Geo) FlipCoordinates() {}  // 转换Lat,Lng 位置
func (g Geo) Wgs2gcj(){} // 经纬度坐标系转换 wgs-> gcj
func (g Geo) Gcj2bd() {} // 经纬度坐标系转换 gcj->BD09
func (g Geo) Wgs2bd() {} // 经纬度坐标系转换 wgs->BD09
func (g Geo) Box() []float64 {}  // 方框边界 minx, miny, maxx, maxy 
 
func Wgs2gcj(lon, lat float64) (float64, float64){}  // WGS坐标系 ----> GCJ坐标系
func Gcj2bd(lon, lat float64) (float64, float64){}   //  火星(GCJ-02)坐标系 ----> 百度(BD-09)坐标系
func Gcj2Wgs(lon, lat float64) (float64, float64){}   //  火星(GCJ-02)坐标系 ----> WGS坐标系
func Bd2gcj(lon, lat float64) (float64, float64) {}  //  百度(BD-09)坐标系 ----> 火星(GCJ-02)坐标系
func Wgs2bd(lon, lat float64) (float64, float64) {}  // WGS坐标系 ----> 百度坐标系

func Wgs2Tile(lng, lat float64, z int) (x, y int) {} //瓦片:lnglat转XY
func Tile2Wgs(x, y, z int) (lat, lng float64) {} //瓦片:XY转lnglat

func Bd09ToTile(x, y float64, zoom int) (int, int) {} //百度经纬度转换为瓦片编号
func MercatorToBd09(x, y float64) (float64, float64) {} //墨卡托坐标转百度经纬度坐标
func Bd09ToMercator(lng, lat float64) (float64, float64){} //百度经纬度坐标转墨卡托坐标

func Azimuth(lon1, lat1, lon2, lat2 float64) float64 {} // P1到P2 的方位角
func PointDistance(lon1, lat1, lon2, lat2 float64) float64 {} // 两经纬度距离
func PointDistHaversine(lon1, lat1, lon2, lat2 float64) float64 {} // 两经纬度距离
func PointMid(lon1, lat1, lon2, lat2 float64) (float64, float64) {} // P1和P2中间点
func PointAt(lon, lat, dist, azimuth float64) (float64, float64) {} // 根据起点、距离、方位角计算另一个点

func ToFixed(f float64, n int) float64 {}    // 浮点数保留

/**身份证**/
func IDsumY(id string) string {} 	// IDsumY 计算身份证的第十八位校验码
func ID15to18(id string) string {} 	// ID15to18 将15位身份证转换为18位的
func IDisValid(id string) bool {} 	// IDisValid 校验身份证第18位是否正确
func IDisPattern(id string) bool {} 	// IDisPattern 二代身份证正则表达式
func NewIDCard(id string) (c IDCard, err error) {} 	// NewIDCard  获取身份证信息


/**地址解析**/
func NewMapAPI(ak string) MapAPI {}  //高德、百度地址解析封装
func (m MapAPI) AmapGeoCode(address string) (poi Poi) {} //高德地址解析
func (m MapAPI) BdmapGeoCode(address string) (poi Poi) {} //百度地址解析
func (m *MapAPI) AmapGeoCodeALL(addrsMap map[string]string, poolsize int) (addrsAll map[string]Poi) {} //多线程解析
func (m *MapAPI) BdmapGeoCodeALL(addrsMap map[string]string, poolsize int) (addrsAll map[string]Poi) {} //多线程解析

reference

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ChinaAddr map[string]string

Functions

func Abs

func Abs(n int64) int64

Abs 整数绝对值 https://segmentfault.com/a/1190000013201491

func AnyToDecimal

func AnyToDecimal(num string, n int) int

任意进制转10进制

func AvgFloat64

func AvgFloat64(i []float64) float64

func Azimuth

func Azimuth(lon1, lat1, lon2, lat2 float64) float64

Azimuth bearing between the two GPS points

func Bd09ToMercator

func Bd09ToMercator(lng, lat float64) (float64, float64)

Bd09ToMercator 百度经纬度坐标转墨卡托坐标

func Bd09ToTile

func Bd09ToTile(lng, lat float64, zoom int) (int, int)

Bd09ToTile 百度经纬度转换为瓦片编号

func Bd2Wgs

func Bd2Wgs(lon, lat float64) (float64, float64)

Bd2Wgs 百度坐标系 ----> WGS坐标系

func Bd2gcj

func Bd2gcj(lon, lat float64) (float64, float64)

Bd2gcj 百度(BD-09)坐标系 ----> 火星(GCJ-02)坐标系

func ColFloat64

func ColFloat64(raw, fields, oper string) (ret float64)

func CsvWriteALL

func CsvWriteALL(data [][]string, wfile string, comma rune) error

CsvWriteALL 生成CSV

func CsvWriteFile

func CsvWriteFile(data [][]string, wfile string, comma string) error

CsvWriteALL 生成CSV

func DayLastRange

func DayLastRange(f string) (ret []string)

DayLastRange 上周/上月/昨天

func DecimalToAny

func DecimalToAny(num, n int) string

10进制转任意进制

func Degrees

func Degrees(d float64) float64

Degrees Degrees

func DiffSqrtMeanFloat64

func DiffSqrtMeanFloat64(a []float64) []float64

func FileCopy

func FileCopy(src, dest string) error

FileCopy 文件/文件夹/链接复制

func FileHash

func FileHash(htype string, fname string) ([]byte, error)

FileHash Hash

func FileLinesCount

func FileLinesCount(filename string, delim byte) int

FileLinesCount 文件行数计算

func FileMD5

func FileMD5(fname string) ([]byte, error)

FileMD5 MD5

func FilePatternLinesCount

func FilePatternLinesCount(fexp string, delim byte) (count int, detail map[string]int)

FilePatternLinesCount 匹配文件行数计算

func FileSHA1

func FileSHA1(fname string) ([]byte, error)

FileSHA1 SHA1

func FileSize

func FileSize(fname string) int64

func Gcj2Wgs

func Gcj2Wgs(lon, lat float64) (float64, float64)

Gcj2Wgs GCJ坐标系 ----> WGS坐标系

func Gcj2bd

func Gcj2bd(lon, lat float64) (float64, float64)

Gcj2bd 火星(GCJ-02)坐标系 ----> 百度(BD-09)坐标系

func GetFTPFiles

func GetFTPFiles(ftptype, addr, user, pwd, pasv, localfileprefix string, pattern []string, expectfiles []string) (files map[string]string, err error)

GetFTPFiles 获取 FTP/SFTP 匹配的文件

func ID15to18

func ID15to18(id string) string

ID15to18 将15位身份证转换为18位的

func IDisPattern

func IDisPattern(id string) bool

IDisPattern 二代身份证正则表达式

func IDisValid

func IDisValid(id string) bool

IDisValid 校验身份证第18位是否正确

func IDsumY

func IDsumY(id string) string

IDsumY 计算身份证的第十八位校验码

func InitAddr

func InitAddr()

init 初始化 加载行政区信息

func Ip2long

func Ip2long(ip net.IP) uint32

func IsClockwise

func IsClockwise(latlngs [][]float64) bool

IsClockwise Green公式判断顺时针

func IsDirsExist

func IsDirsExist(paths []string, isCreate bool) (err error)

IsDirsExist 文件夹是否存在

func IsFilesExist

func IsFilesExist(paths []string) (err error)

IsFileExist 文件是否存在

func Long2ip

func Long2ip(ip uint32) net.IP

func MaxFloat64

func MaxFloat64(i []float64) float64

func MeanFloat64

func MeanFloat64(i []float64) float64

func MercatorToBd09

func MercatorToBd09(x, y float64) (float64, float64)

MercatorToBd09 墨卡托坐标转百度经纬度坐标

func MinFloat64

func MinFloat64(i []float64) float64

func ParsrLS

func ParsrLS(s string) (fileInfo []string)

func PointAt

func PointAt(lon, lat, dist, azimuth float64) (float64, float64)

PointAt Destination point given distance and bearing from start point

func PointDistHaversine

func PointDistHaversine(lon1, lat1, lon2, lat2 float64) float64

PointDistHaversine (in meter) Haversine_formula

func PointDistance

func PointDistance(lon1, lat1, lon2, lat2 float64) float64

PointDistance (in meter) Spherical_law_of_cosines

func PointMid

func PointMid(lon1, lat1, lon2, lat2 float64) (float64, float64)

PointMid 两点间的中间点

func PointRound6

func PointRound6(x, y float64) (float64, float64)

PointRound6 PointRound6

func PointRound7

func PointRound7(x, y float64) (float64, float64)

PointRound7 PointRound7

func PointRound8

func PointRound8(x, y float64) (float64, float64)

PointRound8 PointRound8

func Radians

func Radians(r float64) float64

Radians Radians

func Round

func Round(x float64, prec int) float64

Round Round

func Sqlldr

func Sqlldr(timeflag, userid, data, control, baddir string) (
	rows, badrows int, err error)

Sqlldr 执行成功返回入库记录数,失败则保留log和data到baddir

func StdDevFloat64

func StdDevFloat64(a []float64) float64

func StringReverse

func StringReverse(s string) string

StringReverse reverses a string

func StringToFloat64

func StringToFloat64(raw, fields string) (dat []float64)

func StringsIntersect

func StringsIntersect(s1, s2 []string) []string

StringsIntersect 交集 s1∩s2 去重

func StringsMinus

func StringsMinus(s1, s2 []string) []string

StringsMinus 差集s1-s2

func StringsReverse

func StringsReverse(s []string) []string

StringsReverse reverses an array of string

func StringsUnion

func StringsUnion(s1, s2 []string) []string

StringsUnion 并集 s1∪s2 去重

func StringsUniq

func StringsUniq(s1 []string) []string

StringsUniq 去重

func SubString

func SubString(str string, begin, length int) (substr string)

func SumFloat64

func SumFloat64(s []float64) (sum float64)

func Tile2Wgs

func Tile2Wgs(x, y, z int) (lat, lng float64)

Tile2Wgs 瓦片:XY转lnglat

func TileImage

func TileImage(lng, lat float64, z int, deg int) (x, y, px, py int)

TileImage 经纬度转瓦片像素点位置

func TimeExtend

func TimeExtend(t time.Time, s int, d time.Duration) (r []time.Time)

func TimeFormat

func TimeFormat(f string, t ...time.Time) (ret []string)

func TimeParse

func TimeParse(s string) (t time.Time, err error)

func TimeRule

func TimeRule(s string, t time.Time, sum int) (ret []time.Time)

func TimeSplit

func TimeSplit(b, e time.Time, d time.Duration) (r []time.Time)

func TimeTrunc

func TimeTrunc(s string, t time.Time) time.Time

func Unzip

func Unzip(fname, oname string) error

func Wgs2Tile

func Wgs2Tile(lng, lat float64, z int) (x, y int)

Wgs2Tile 瓦片:lnglat转XY

func Wgs2bd

func Wgs2bd(lon, lat float64) (float64, float64)

Wgs2bd WGS坐标系 ----> 百度坐标系

func Wgs2gcj

func Wgs2gcj(lon, lat float64) (float64, float64)

Wgs2gcj WGS坐标系 ----> GCJ坐标系

func ZipDeCompress

func ZipDeCompress(fname string) (retRaw map[string][]byte, err error)

ZipDeCompress ZIP解压

Types

type Crypto

type Crypto struct {
	Key, IV                  []byte
	Algorithm, Mode, Padding string
}

func NewCrypto

func NewCrypto(key []byte) Crypto

func (*Crypto) Decrypt

func (c *Crypto) Decrypt(data []byte) (dst []byte, err error)

func (*Crypto) Encrypt

func (c *Crypto) Encrypt(data []byte) (dst []byte, err error)

================================================================================================

type Geo

type Geo struct {
	Type   string
	Coords [][][][]float64
}

func FromGeoJSON

func FromGeoJSON(geojson string) (g Geo, err error)

FromGeoJSON 解析GeoJSON为Geo

func FromWKT

func FromWKT(wkt string) (g Geo, err error)

FromWKT 解析WKT为Geo

func (Geo) Box

func (g Geo) Box() []float64

Box 方框边界 minx, miny, maxx, maxy

func (Geo) CoordsJSON

func (g Geo) CoordsJSON() (s string, err error)

func (Geo) Copy

func (g Geo) Copy() Geo

Copy CopyGeo

func (Geo) FlipCoordinates

func (g Geo) FlipCoordinates()

FlipCoordinates 转换Lat,Lng 位置

func (Geo) Gcj2bd

func (g Geo) Gcj2bd()

Gcj2bd 经纬度坐标系转换 gcj->BD09

func (Geo) GeoJSON

func (g Geo) GeoJSON() (s string, err error)

GeoJSON 生成GeoJSON

func (Geo) Lines

func (g Geo) Lines() []Line

func (Geo) PointFunc

func (g Geo) PointFunc(f func(lon, lat float64) (float64, float64))

PointFunc 对所有点应用函数

func (Geo) PointRound6

func (g Geo) PointRound6()

PointRound6 PointRound6

func (Geo) PointRound7

func (g Geo) PointRound7()

PointRound7 PointRound7

func (Geo) PointRound8

func (g Geo) PointRound8()

PointRound8 PointRound8

func (Geo) Points

func (g Geo) Points() []Point

func (Geo) String

func (g Geo) String() (wkt string)

func (Geo) ToWKT

func (g Geo) ToWKT() (wkt string)

ToWKT 生成WKT

func (Geo) Wgs2bd

func (g Geo) Wgs2bd()

Wgs2bd 经纬度坐标系转换 wgs->BD09

func (Geo) Wgs2gcj

func (g Geo) Wgs2gcj()

Wgs2gcj 经纬度坐标系转换 wgs-> gcj

type Hash

type Hash struct{ Data string }

Hash Hash

func NewHash

func NewHash(dat string) Hash

NewHash NewHash

func (Hash) MD5

func (h Hash) MD5() string

MD5 MD5

func (Hash) SHA1

func (h Hash) SHA1() string

SHA1 SHA1

type IDCard

type IDCard struct {
	ID        string
	Gender    string
	Age       string
	Birthdate string
	Province  string
	City      string
	District  string
}

* 身份证15位编码规则:dddddd yymmdd xx p * 身份证18位编码规则:dddddd yyyymmdd xx p y * dddddd: 地区编码 * yymmdd: 出生年(两位年)月日,如:910215 * yyyymmdd: 出生年(四位年)月日,如:19910215 * xx: 顺序编码,系统产生,无法确定 * p: 性别,奇数为男,偶数为女 * y: 校验码,该位数值可通过前17位计算获得 * * 前17位号码加权因子为 Wi = [ 7, 9, 10, 5, 8, 4, 2, 1, 6, 3, 7, 9, 10, 5, 8, 4, 2 ] * 验证位 Y = [ 1, 0, 10, 9, 8, 7, 6, 5, 4, 3, 2 ] * 如果验证码恰好是10,为了保证身份证是十八位,那么第十八位将用X来代替 * 校验位计算: Y_P = mod( ∑(Ai×Wi),11 ) * i为身份证号码1...17 位; Y_P为校验码Y所在校验码数组位置

func NewIDCard

func NewIDCard(id string) (c IDCard, err error)

NewIDCard 获取身份证信息

type Line

type Line struct {
	P1 Point
	P2 Point
}

type MapAPI

type MapAPI struct {
	AK        string
	LimitCity string
	SM        sync.Map
	// contains filtered or unexported fields
}

func NewMapAPI

func NewMapAPI(ak string) MapAPI

func (MapAPI) AmapGeoCode

func (m MapAPI) AmapGeoCode(address string) (poi Poi)

AmapGeoCode 高德解析地址为经纬度

func (*MapAPI) AmapGeoCodeALL

func (m *MapAPI) AmapGeoCodeALL(addrsMap map[string]string, poolsize int) (addrsAll map[string]Poi)

AmapGeoCodeALL 高德解析地址为经纬度

func (MapAPI) BdmapGeoCode

func (m MapAPI) BdmapGeoCode(address string) (poi Poi)

BdmapGeoCode 百度解析地址为经纬度

func (*MapAPI) BdmapGeoCodeALL

func (m *MapAPI) BdmapGeoCodeALL(addrsMap map[string]string, poolsize int) (addrsAll map[string]Poi)

BdmapGeoCodeALL 百度解析地址为经纬度

func (MapAPI) BmapMocator

func (m MapAPI) BmapMocator(mocator string) string

BmapMocator 百度墨卡托解析

type Poi

type Poi struct {
	Status   int
	Message  string
	Lng      float64
	Lat      float64
	Addr     string
	Province string
	City     string
	District string
	CityCode string
	Level    string
	Info     map[string]string
}

type Point

type Point struct {
	X float64
	Y float64
}

func NewPoint

func NewPoint(x, y string) (p Point, err error)

func (*Point) Gcj2bd

func (p *Point) Gcj2bd()

func (*Point) ReverseXY

func (p *Point) ReverseXY()

func (Point) String

func (p Point) String() string

func (*Point) Wgs2bd

func (p *Point) Wgs2bd()

func (*Point) Wgs2gcj

func (p *Point) Wgs2gcj()

type SSftp

type SSftp struct {
	Ssh  *ssh.Client
	Sftp *sftp.Client
}

func NewSSftp

func NewSSftp(user, passwd, hostport string) (s SSftp, err error)

func (SSftp) Close

func (s SSftp) Close() error

func (SSftp) Get

func (s SSftp) Get(scpfiles [][2]string) error

func (SSftp) Put

func (s SSftp) Put(scpfiles [][2]string) error

type XFtp

type XFtp struct {
	Addr            string
	User            string
	Pwd             string
	PASV            string
	FilePattern     []string
	LocalFilePrefix string
	Conn            *ftp4go.FTP
}

func (*XFtp) Connect

func (c *XFtp) Connect() (err error)

func (*XFtp) ConnectAndDownload

func (c *XFtp) ConnectAndDownload() (files map[string]string, err error)

func (XFtp) DownloadFiles

func (c XFtp) DownloadFiles(files []string) (dat map[string]string, err error)

func (XFtp) DownloadFilesMap

func (c XFtp) DownloadFilesMap(files map[string]string) (dat map[string]string, err error)

func (XFtp) FileList

func (c XFtp) FileList(CMD string) (ftpfiles []string)

func (XFtp) InfoList

func (c XFtp) InfoList() (ftpfiles []string)

func (XFtp) Logout

func (c XFtp) Logout() error

func (XFtp) MKdir

func (c XFtp) MKdir(path string)

func (XFtp) NameList

func (c XFtp) NameList() (ftpfiles []string)

func (XFtp) Size

func (c XFtp) Size(path string) int64

func (*XFtp) UploadFiles

func (c *XFtp) UploadFiles(files map[string]string, useLineMode bool) (retInfo map[string]error)

type XSFtp

type XSFtp struct {
	Addr            string
	User            string
	Pwd             string
	FilePattern     []string
	LocalFilePrefix string
	SSH             *ssh.Client
	SFTP            *sftp.Client
}

func (*XSFtp) Cmd

func (c *XSFtp) Cmd(cmd string) (stdout, stderr string)

func (*XSFtp) Connect

func (c *XSFtp) Connect() (err error)

func (*XSFtp) ConnectAndDownload

func (c *XSFtp) ConnectAndDownload() (files map[string]string, err error)

func (*XSFtp) DownloadFiles

func (c *XSFtp) DownloadFiles(files []string) (dat map[string]string, err error)

func (*XSFtp) DownloadFilesMap

func (c *XSFtp) DownloadFilesMap(files map[string]string) (dat map[string]string, err error)

func (XSFtp) FileExist

func (c XSFtp) FileExist(filepath string) (bool, error)

FileExist 文件是否存在

func (XSFtp) IsDir

func (c XSFtp) IsDir(path string) bool

IsDir 检查远程是否是个目录

func (XSFtp) IsFile

func (c XSFtp) IsFile(path string) bool

IsFile 检查远程是否是个文件

func (XSFtp) Logout

func (c XSFtp) Logout() error

func (*XSFtp) NameList

func (c *XSFtp) NameList() (ftpfiles []string)

------------------------------------------------------------------------------

func (XSFtp) RemoveFile

func (c XSFtp) RemoveFile(remoteFile string) error

func (XSFtp) Size

func (c XSFtp) Size(path string) int64

Size 获取文件大小

func (*XSFtp) UploadFiles

func (c *XSFtp) UploadFiles(files map[string]string) (retInfo map[string]error)

Jump to

Keyboard shortcuts

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