Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Read shapfile with Multipolygon #44

Open
gonponlotus opened this issue Jul 15, 2020 · 1 comment
Open

Read shapfile with Multipolygon #44

gonponlotus opened this issue Jul 15, 2020 · 1 comment

Comments

@gonponlotus
Copy link

Hi everyone,
how can i read shapefile with the geom is multipolygon and convert to array list polygon

thank you

@wangxin0814
Copy link

geomentry := (metaData.Shape).(*goShp.Polygon)

			coords := [][]geom.Coord{}
			for i := int32(0); i < geomentry.NumParts; i++ {
				coord := []geom.Coord{}

				if i == 0 {
					if geomentry.NumParts > 1 {
						for _, point := range geomentry.Points[0:geomentry.Parts[i+1]] {
							coord = append(coord, []float64{point.X, point.Y})
						}
						coords = append(coords, coord)
					} else { // 只有一个部分
						for _, point := range geomentry.Points[0:] {
							coord = append(coord, []float64{point.X, point.Y})
						}
						coords = append(coords, coord)
					}
				} else if i == geomentry.NumParts-1 {
					for _, point := range geomentry.Points[geomentry.Parts[i]:] {
						coord = append(coord, []float64{point.X, point.Y})
					}
					coords = append(coords, coord)
				} else {
					for _, point := range geomentry.Points[geomentry.Parts[i]:geomentry.Parts[i+1]] {
						coord = append(coord, []float64{point.X, point.Y})
					}
					coords = append(coords, coord)
				}
			}

			polygon := geom.NewPolygon(geom.XY).MustSetCoords(coords).SetSRID(4326)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants