본문 바로가기

Web_Application/C#

[C#][EF] 들어오는 TDS(Tabular Data Stream)의 RPC(원격 프로시저 호 출) 프로토콜 스트림이 잘못되었습니다. 매개 변수 1("@0_0"): 제공된 값이 데이터 형식 geography의 잘못된 인스턴스입니다. 원본 데이..



들어오는 TDS(Tabular Data Stream)의 RPC(원격 프로시저 호 출) 프로토콜 스트림이 잘못되었습니다. 

매개 변수 1("@0_0"): 제공된 값이 데이터 형식 geography의 잘못된 인스턴스입니다. 

원본 데이터에 잘못된 값이 있는지 확인하십시오. 

잘못된 값의 예로는 소수 자릿수가 전체 자릿수보다 큰 숫자 형식의 데이터를 들 수 있습니다.


shp  파일에서 geometry data type 을 geography type으로 변환 후 EF6 -> mssql bulk insert 과정에서 만난 에러메세지 입니다.


참고 : https://www.exceptionnotfound.net/fixing-sql-server-spatial-not-a-valid-instance-of-geography-errors-in-c-sharp/


geometry -> geography 로 좌표계를 적용하면 lat, lng 의 +/- 가 변경되는 경우를 만났습니다. 거울에 비친듯한 투영(자세한 용어는 잘 모르겠습니다.) geometry 의 폴리곤의 시작점과 끝점은 geography 의 시작점과 끝점이 다름에서 시작되는 문제인 거 같습니다.


제가 적용한 C# 코드

                            if (geometry.STIsValid())
                            {
                                var tempGeography = SqlGeography.STGeomFromText(new SqlChars(dbGeography.AsText()), 4326).MakeValid();
                                var invertedSqlGeography = tempGeography.ReorientObject();

                                if (tempGeography.STArea() > invertedSqlGeography.STArea())
                                    tempGeography = invertedSqlGeography;

                                schoolPolygon.geography = DbGeography.PolygonFromText(tempGeography.ToString(), 4326);    
                                // DbSpatialServices.Default.GeographyFromProviderValue(tempGeography);
                            }