示例#1
0
bool ShapelibProxy::query(const std::string &handle, std::string &errorMessage, 
   const std::string &whereClause, const std::string &labelFormat,
   LocationType minClip, LocationType maxClip, const CoordinateTransformation* pCoordinateTransformation)
{
   std::map<std::string, ShapelibHandle>::iterator iter = mHandles.find(handle);
   if (iter == mHandles.end())
   {
      errorMessage = "Could not find handle";
      return false;
   }
   ShapelibHandle& shapelibHandle = iter->second;

   if (!whereClause.empty())
   {
      errorMessage = "Shapelib does not support where clauses";
      return false;
   }

   std::string formattedLabel = preprocessFormatString(shapelibHandle, labelFormat);

   int count = 0;
   ArcProxyLib::FeatureType featureType = ArcProxyLib::UNKNOWN;
   if (!getTypeAndCount(shapelibHandle, errorMessage, featureType, count))
   {
      return false;
   }

   for (int i = 0; i < count; ++i)
   {
      SHPObject* pShpObject = SHPReadObject(shapelibHandle.getShpHandle(), i);
      if (pShpObject == NULL)
      {
         continue;
      }

      // Convert from shapefile coordinates to application coordinates.
      double minX = pShpObject->dfXMin;
      double maxX = pShpObject->dfXMax;
      double minY = pShpObject->dfYMin;
      double maxY = pShpObject->dfYMax;
      if (pCoordinateTransformation != NULL)
      {
         if (pCoordinateTransformation->translateShapeToApp(minX, minY, minX, minY) == false ||
            pCoordinateTransformation->translateShapeToApp(maxX, maxY, maxX, maxY) == false)
         {
            errorMessage = "Coordinate transformation failed for bounding box. Check the .prj file and try again.";
            return false;
         }
      }

      QRectF objectRect(QPointF(minY, minX), QPointF(maxY, maxX));
      QRectF clipRect(QPointF(minClip.mX, minClip.mY), QPointF(maxClip.mX, maxClip.mY));

      if ((clipRect.isEmpty() == true) ||
         ((objectRect.isEmpty() == true) && (clipRect.contains(objectRect.topLeft()) == true)) ||
         (objectRect.intersects(clipRect) == true))
      {
         ArcProxyLib::Feature feature;
         feature.setType(featureType);

         std::vector<std::pair<double, double> > vertices(pShpObject->nVertices);
         for (int vertex = 0; vertex < pShpObject->nVertices; ++vertex)
         {
            // Convert from shapefile coordinates to application coordinates.
            double vertexX = pShpObject->padfX[vertex];
            double vertexY = pShpObject->padfY[vertex];
            if (pCoordinateTransformation != NULL)
            {
               if (pCoordinateTransformation->translateShapeToApp(vertexX, vertexY, vertexX, vertexY) == false)
               {
                  errorMessage = "Coordinate transformation failed for vertex. Check the .prj file and try again.";
                  return false;
               }
            }

            vertices[vertex] = std::make_pair(vertexY, vertexX);
         }

         feature.setVertices(vertices);

         for (int path = 0; path < pShpObject->nParts; ++path)
         {
            feature.addPathAtIndex(pShpObject->panPartStart[path]);
         }

         feature.setLabel(std::for_each(formattedLabel.begin(), formattedLabel.end(), ShapelibFormatStringProcessor(
            shapelibHandle, i)).getProcessedString());

         std::vector<std::string> attributes;
         int fieldCount = DBFGetFieldCount(shapelibHandle.getDbfHandle());
         for (int field = 0; field < fieldCount; ++field)
         {
            std::string name;
            std::string type;
            std::string value;
            if (getFieldAttributes(shapelibHandle, name, type, value, field, i))
            {
               attributes.push_back(value);
            }
         }
         feature.setAttributes(attributes);
         emit featureLoaded(feature);
      }

      SHPDestroyObject(pShpObject);
   }

   return true;
}
示例#2
0
int PrinceEngine::getMob(Common::Array<Mob> &mobList, bool usePriorityList, int posX, int posY) {

	Common::Point pointPos(posX, posY);

	int mobListSize;
	if (usePriorityList) {
		mobListSize = _mobPriorityList.size();
	} else {
		mobListSize = mobList.size();
	}

	for (int mobNumber = 0; mobNumber < mobListSize; mobNumber++) {
		Mob *mob = nullptr;
		if (usePriorityList) {
			mob = &mobList[_mobPriorityList[mobNumber]];
		} else {
			mob = &mobList[mobNumber];
		}

		if (mob->_visible) {
			continue;
		}

		int type = mob->_type & 7;
		switch (type) {
		case 0:
		case 1:
			//normal_mob
			if (!mob->_rect.contains(pointPos)) {
				continue;
			}
			break;
		case 3:
			//mob_obj
			if (mob->_mask < kMaxObjects) {
				int nr = _objSlot[mob->_mask];
				if (nr != 0xFF) {
					Object &obj = *_objList[nr];
					Common::Rect objectRect(obj._x, obj._y, obj._x + obj._width, obj._y + obj._height);
					if (objectRect.contains(pointPos)) {
						Graphics::Surface *objSurface = obj.getSurface();
						byte *pixel = (byte *)objSurface->getBasePtr(posX - obj._x, posY - obj._y);
						if (*pixel != 255) {
							break;
						}
					}
				}
			}
			continue;
			break;
		case 2:
		case 5:
			//check_ba_mob
			if (!_backAnimList[mob->_mask].backAnims.empty()) {
				int currentAnim = _backAnimList[mob->_mask]._seq._currRelative;
				Anim &backAnim = _backAnimList[mob->_mask].backAnims[currentAnim];
				if (backAnim._animData != nullptr) {
					if (!backAnim._state) {
						Common::Rect backAnimRect(backAnim._currX, backAnim._currY, backAnim._currX + backAnim._currW, backAnim._currY + backAnim._currH);
						if (backAnimRect.contains(pointPos)) {
							int phase = backAnim._showFrame;
							int phaseFrameIndex = backAnim._animData->getPhaseFrameIndex(phase);
							Graphics::Surface *backAnimSurface = backAnim._animData->getFrame(phaseFrameIndex);
							byte pixel = *(byte *)backAnimSurface->getBasePtr(posX - backAnim._currX, posY - backAnim._currY);
							if (pixel != 255) {
								if (type == 5) {
									if (mob->_rect.contains(pointPos)) {
										break;
									}
								} else {
									break;
								}
							}
						}
					}
				}
			}
			continue;
			break;
		default:
			//not_part_ba
			continue;
			break;
		}

		if (usePriorityList) {
			return _mobPriorityList[mobNumber];
		} else {
			return mobNumber;
		}
	}
	return -1;
}