我正在尝试将天气雷达图像叠加到地图上。我得到了图像及其世界数据文件,该文件告诉我将其覆盖在地图上的位置。我必须根据与图像关联的数据来计算图像的mapRect。我的mapRect似乎无法正确通过,因此我遵循了让常量deltaX和deltaY的代码。 deltaX有一个断点,所以我可以看到发生了什么。当我跨过deltaX时,它将正确分配该值。当我越过deltaY时,deltaX的数据消失,然后deltaY的数据消失。
功能如下:
func parseWorldFileData(worldFileStringToParse: String) -> (worldFileDataStruct) {
worldFileDataToParse = worldFileStringToParse.components(separatedBy: "\n") //componentsSeparatedByString("\n")
for i in 0...5 {
worldFileDataToParse[i] = String(worldFileDataToParse[i].characters.dropLast(2))
}
if self.worldFileDataToParse.count >= 6 {
worldFileData.xDimension = Double(self.worldFileDataToParse[0])!
worldFileData.rotationParam1 = Double(self.worldFileDataToParse[1])!
worldFileData.rotationParam2 = Double(self.worldFileDataToParse[2])!
worldFileData.yDimension = Double(self.worldFileDataToParse[3])!
worldFileData.xCoordinate = (Double(self.worldFileDataToParse[4])! as CLLocationDegrees)
worldFileData.yCoordinate = (Double(self.worldFileDataToParse[5])! as CLLocationDegrees)
worldFileData.easternLongitude = (self.worldFileData.xCoordinate + ((Double(self.worldFileData.imageWidth)) * self.worldFileData.xDimension) as CLLocationDegrees)
worldFileData.southernLatitude = (self.worldFileData.yCoordinate + ((Double(self.worldFileData.imageHeight)) * self.worldFileData.yDimension) as CLLocationDegrees)
let deltaX = fabs(self.worldFileData.xCoordinate - self.worldFileData.easternLongitude)
let deltaY = fabs(self.worldFileData.yCoordinate - self.worldFileData.southernLatitude)
worldFileData.boundingMapRect = MKMapRectMake(self.worldFileData.xCoordinate, //topLeft.x
self.worldFileData.yCoordinate, //topLeft.y
deltaX, //fabs(topLeft.x-topRight.x)
deltaY) //fabs(topLeft.y - bottomLeft.y)
worldFileData.midCoordinate = CLLocationCoordinate2D(latitude:((self.worldFileData.southernLatitude + (self.worldFileData.yCoordinate - self.worldFileData.southernLatitude)/2) as CLLocationDegrees), longitude: ((self.worldFileData.xCoordinate + (self.worldFileData.easternLongitude - self.worldFileData.xCoordinate)/2) as CLLocationDegrees))
} else { print("Error parsing WorldData file.") }
return worldFileData
}
在逐步使用delX之前,数据为:
worldFileStringToParse String "0.00925265225497161\r\n0.000000\r\n0.000000\r\n-0.00925265225497161\r\n-80.2491661765359\r\n41.5148515181108\r\n"
self WeatherFun.WorldFileDataModel 0x000060000033b260
worldFileDataToParse [String] 7 values
worldFileData WeatherFun.WorldFileDataModel.worldFileDataStruct
xDimension Double 0.0092526522549715995
rotationParam1 Double 0
rotationParam2 Double 0
yDimension Double -0.0092526522549715995
xCoordinate CLLocationDegrees -80.249166176534999
yCoordinate CLLocationDegrees 41.51485151811
imageHeight Double 183.33333333333334
imageWidth Double 200
easternLongitude CLLocationDegrees -78.398635725540686
southernLatitude CLLocationDegrees 39.818531938031875
boundingMapRect MKMapRect
midCoordinate CLLocationCoordinate2D
deltaX CLLocationDegrees
deltaY CLLocationDegrees
在deltaX步骤之后的数据如下:
worldFileStringToParse String "0.00925265225497161\r\n0.000000\r\n0.000000\r\n-0.00925265225497161\r\n-80.2491661765359\r\n41.5148515181108\r\n"
self WeatherFun.WorldFileDataModel 0x000060000033b260
worldFileDataToParse [String] 7 values
worldFileData WeatherFun.WorldFileDataModel.worldFileDataStruct
xDimension Double 0.0092526522549715995
rotationParam1 Double 0
rotationParam2 Double 0
yDimension Double -0.0092526522549715995
xCoordinate CLLocationDegrees -80.249166176534999
yCoordinate CLLocationDegrees 41.51485151811
imageHeight Double 183.33333333333334
imageWidth Double 200
easternLongitude CLLocationDegrees -78.398635725540686
southernLatitude CLLocationDegrees 39.818531938031875
boundingMapRect MKMapRect
midCoordinate CLLocationCoordinate2D
deltaX CLLocationDegrees 1.850530450994313
deltaY CLLocationDegrees
跨步增量时,数据为:
worldFileStringToParse String "0.00925265225497161\r\n0.000000\r\n0.000000\r\n-0.00925265225497161\r\n-80.2491661765359\r\n41.5148515181108\r\n"
self WeatherFun.WorldFileDataModel 0x000060000033b260
worldFileDataToParse [String] 7 values
worldFileData WeatherFun.WorldFileDataModel.worldFileDataStruct
xDimension Double 0.0092526522549715995
rotationParam1 Double 0
rotationParam2 Double 0
yDimension Double -0.0092526522549715995
xCoordinate CLLocationDegrees -80.249166176534999
yCoordinate CLLocationDegrees 41.51485151811
imageHeight Double 183.33333333333334
imageWidth Double 200
easternLongitude CLLocationDegrees -78.398635725540686
southernLatitude CLLocationDegrees 39.818531938031875
boundingMapRect MKMapRect
midCoordinate CLLocationCoordinate2D
deltaX CLLocationDegrees
deltaY CLLocationDegrees 1.696319580078125
当我进入boundingMapRect计算时,这是我的数据:
worldFileStringToParse String "0.00925265225497161\r\n0.000000\r\n0.000000\r\n-0.00925265225497161\r\n-80.2491661765359\r\n41.5148515181108\r\n"
self WeatherFun.WorldFileDataModel 0x000060000033b260
worldFileDataToParse [String] 7 values
worldFileData WeatherFun.WorldFileDataModel.worldFileDataStruct
xDimension Double 0.0092526522549715995
rotationParam1 Double 0
rotationParam2 Double 0
yDimension Double -0.0092526522549715995
xCoordinate CLLocationDegrees -80.249166176534999
yCoordinate CLLocationDegrees 41.51485151811
imageHeight Double 183.33333333333334
imageWidth Double 200
easternLongitude CLLocationDegrees -78.398635725540686
southernLatitude CLLocationDegrees 39.818531938031875
boundingMapRect MKMapRect
midCoordinate CLLocationCoordinate2D
deltaX CLLocationDegrees
deltaY CLLocationDegrees
有人对正在发生的事情有任何线索吗?该计算似乎是正确的,因为覆盖mapRect应该跨越地图上的该距离。但是,当输入boundingMapRect的计算时,我的deltaX似乎消失了。救命!!!
最佳答案
继续进行之后,数据再次出现。我不知道为什么会这样,这有点令人不安,但是我对未来的建议是始终遵循。
关于swift - Swift-让常量值消失到下一行,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/43969220/